fb9eb3322d0564cdf1e7e11fb7647641785ef93b — Robin Watts 10 months ago 6210780
Tweak pdf_update_stream to work better with undo.

Set the new length in the object before we update the stream.
Setting the new length has the effect of moving/copying the
old object/old stream into the journal. Previously we were
setting the stream, THEN moving the old version which meant
the new stream was copied in to accompany the old object.
1 files changed, 5 insertions(+), 1 deletions(-)

M source/pdf/pdf-xref.c
M source/pdf/pdf-xref.c => source/pdf/pdf-xref.c +5 -1
@@ 2543,10 2543,14 @@ pdf_update_stream(fz_context *ctx, pdf_document *doc, pdf_obj *obj, fz_buffer *n
		x = pdf_get_xref_entry(ctx, doc, num);

	/* Write the Length first, as this has the effect of moving the
	 * old object into the journal for undo. This also moves the
	 * stream buffer with it, keeping it consistent. */
	pdf_dict_put_int(ctx, obj, PDF_NAME(Length), (int)fz_buffer_storage(ctx, newbuf, NULL));

	fz_drop_buffer(ctx, x->stm_buf);
	x->stm_buf = fz_keep_buffer(ctx, newbuf);

	pdf_dict_put_int(ctx, obj, PDF_NAME(Length), (int)fz_buffer_storage(ctx, newbuf, NULL));
	if (!compressed)
		pdf_dict_del(ctx, obj, PDF_NAME(Filter));