Bug 694954

Summary: corrupted data output
Product: MuPDF Reporter: Suntor <suntor>
Component: mupdfAssignee: MuPDF bugs <mupdf-bugs>
Status: RESOLVED FIXED    
Severity: critical CC: tor.andersson
Priority: P4    
Version: 1.3   
Hardware: PC   
OS: Windows XP   
Customer: Word Size: ---

Description Suntor 2014-01-15 20:45:52 UTC
Win version mutool.exe from mupdf-1.3-windows.zip.

I tried to extract raw stream data from PDF file with cmd:

'mutool show -b -e src.pdf 7 > 7obj'

but data in 7obj file was corrupted.
All LF symbols were replaced by a pair of CR,LF symbols.
So I decided it was because of the wrong mode of 'stdout'.
By default, 'stdout' mode is _O_TEXT, but for correct output it must be a _O_BINARY.

I downloaded the mupdf-1.3-source.tar.gz source archive and corrected the following in it:

[\mupdf-1.3-source\source\tools\pdfshow.c, line 100]:
In func showstream(int num, int gen), add these lines:

if (showbinary)
	if (-1 == _setmode(_fileno(stdout), _O_BINARY))
		perror("ERROR: Cannot set 'stdout' mode to binary.\n");

As you see, only "-b -e" combination affected. The output for "-b" or "-e" alone wasn't changed. This code for Win version only!

mutool now works properly.

Sorry for my English...
CY, Suntor, Russia
Comment 1 Tor Andersson 2014-04-15 08:19:45 UTC
Use the mutool show -o option (new in version 1.4) to specify an output file instead of using file redirection on windows.