Bug 697469

Summary: digest signature create a wrong byterange
Product: MuPDF Reporter: luoxing <luoxing>
Component: mupdfAssignee: MuPDF bugs <mupdf-bugs>
Status: RESOLVED FIXED    
Severity: major    
Priority: P4    
Version: 1.10   
Hardware: PC   
OS: Windows 10   
Customer: Word Size: ---
Attachments: code pdf,cert password(testtest)

Description luoxing 2017-01-09 20:03:15 UTC
Created attachment 13281 [details]
code pdf,cert password(testtest)

signature byterange error
<</ByteRange[2147483647 2147483647 2147483647 2147483647]/Contents<00000000000000000000000000000000000000000000000000000000000000000....

can't complete the signature
Comment 1 luoxing 2017-01-09 21:50:11 UTC
1.9a is worked an the same code
Comment 2 luoxing 2017-01-10 17:50:55 UTC
the reason is in function pdf_save_document() too early finalise PDF_Write_state, and too late write the file tail。

change the code in pdf_save_document() can resolve the problem.
fz_try(ctx)
	{
		initialise_write_state(ctx, doc, in_opts, &opts); 
		do_pdf_save_document(ctx, doc, &opts, in_opts);
		fz_drop_output(ctx, opts.out);
		opts.out = NULL;
		complete_signatures(ctx, doc, &opts, filename);
	}
	fz_always(ctx)
	{
		finalise_write_state(ctx, &opts);
	}
	fz_catch(ctx)