[Tex/LaTex] includegraphics error when scaling image

errorsgraphicsmiktexpdftex

I have been using Latex for years now, and consider myself fairly fluent, but this error has me stumped. I am using Miktex 2.9 in Windows 7, and am encountering an error in something that up until now has always worked fine for me on other systems.

I get the error:

 ! pdfTeX error (\pdfsetmatrix): Unrecognized format..
<to be read again> 
               \endgroup \set@typeset@protect 
l.9 \end{document}

when compiling with pdflatex and I include an image (png or pdf, haven't tried other formats) and try to resize it using either of the following:

\includegraphics[width=\textwidth]{CQL.pdf}

or

\includegraphics[height=10cm]{CQL.pdf}

However, if I simply use:

\includegraphics{CQL.pdf}

then it all works fine. I have removed all other packages and set the document class to article rather than a custom style, but that doesn't solve the problem. Here is the a minimal piece of code that gives this problem:

\documentclass{article}
\usepackage{graphicx}
\begin{document}

\begin{figure}
\includegraphics[height=10cm]{CQL.pdf}
\end{figure}

\end{document}

Given an option, I would probably just avoid this headache by booting up Ubuntu, but I currently do not have that option (also not in a VM). Can anybody help me?

EDIT: PDF file in question: https://drive.google.com/file/d/0BwRwUW7S2s2HWXMxMEtCeXNOS3c/edit

Log output, including \listfiles output:

This is pdfTeX, Version 3.1415926-2.5-1.40.14 (MiKTeX 2.9) (preloaded
format=pdflatex 2014.2.11)  18 FEB 2014 17:17 entering extended mode
**figtest (C:\Users\andrew.k\Documents\ecai2014\figtest.tex LaTeX2e <2011/06/27> Babel <v3.8m> and hyphenation patterns for english,
afrikaans, ancientgreek, ar abic, armenian, assamese, basque, bengali,
bokmal, bulgarian, catalan, coptic,  croatian, czech, danish, dutch,
esperanto, estonian, farsi, finnish, french, ga lician, german,
german-x-2013-05-26, greek, gujarati, hindi, hungarian, iceland ic,
indonesian, interlingua, irish, italian, kannada, kurmanji, latin,
latvian,  lithuanian, malayalam, marathi, mongolian, mongolianlmc,
monogreek, ngerman, n german-x-2013-05-26, nynorsk, oriya, panjabi,
pinyin, polish, portuguese, roman ian, russian, sanskrit, serbian,
slovak, slovenian, spanish, swedish, swissgerm an, tamil, telugu,
turkish, turkmen, ukenglish, ukrainian, uppersorbian, usengl ishmax,
welsh, loaded. ("C:\Program Files (x86)\MiKTeX
2.9\tex\latex\base\article.cls" Document Class: article 2007/10/19 v1.4h Standard LaTeX document class ("C:\Program Files (x86)\MiKTeX
2.9\tex\latex\base\size10.clo" File: size10.clo 2007/10/19 v1.4h Standard LaTeX file (size option) ) \c@part=\count79
\c@section=\count80 \c@subsection=\count81 \c@subsubsection=\count82
\c@paragraph=\count83 \c@subparagraph=\count84 \c@figure=\count85
\c@table=\count86 \abovecaptionskip=\skip41 \belowcaptionskip=\skip42
\bibindent=\dimen102 ) ("C:\Program Files (x86)\MiKTeX
2.9\tex\latex\graphics\graphicx.sty" Package: graphicx 1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)

("C:\Program Files (x86)\MiKTeX 2.9\tex\latex\graphics\keyval.sty"
Package: keyval 1999/03/16 v1.13 key=value parser (DPC)
\KV@toks@=\toks14 ) ("C:\Program Files (x86)\MiKTeX
2.9\tex\latex\graphics\graphics.sty" Package: graphics 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)

("C:\Program Files (x86)\MiKTeX 2.9\tex\latex\graphics\trig.sty"
Package: trig 1999/03/16 v1.09 sin cos tan (DPC) ) ("C:\Program Files
(x86)\MiKTeX 2.9\tex\latex\00miktex\graphics.cfg" File: graphics.cfg
2007/01/18 v1.5 graphics configuration of teTeX/TeXLive ) Package
graphics Info: Driver file: pdftex.def on input line 91.

("C:\Program Files (x86)\MiKTeX 2.9\tex\latex\pdftex-def\pdftex.def"
File: pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX

("C:\Program Files (x86)\MiKTeX
2.9\tex\generic\oberdiek\infwarerr.sty" Package: infwarerr 2010/04/08 v1.3 Providing info/warning/error messages (HO) ) ("C:\Program Files
(x86)\MiKTeX 2.9\tex\generic\oberdiek\ltxcmds.sty" Package: ltxcmds
2011/11/09 v1.22 LaTeX kernel commands for general use (HO) )
\Gread@gobject=\count87 )) \Gin@req@height=\dimen103
\Gin@req@width=\dimen104 )
(C:\Users\andrew.k\Documents\ecai2014\figtest.aux) LaTeX Font Info:   
Checking defaults for OML/cmm/m/it on input line 6. LaTeX Font Info:  
... okay on input line 6. LaTeX Font Info:    Checking defaults for
T1/cmr/m/n on input line 6. LaTeX Font Info:    ... okay on input line
6. LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 6. LaTeX Font Info:    ... okay on input line 6. LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 6. LaTeX Font Info:  
... okay on input line 6. LaTeX Font Info:    Checking defaults for
OMX/cmex/m/n on input line 6. LaTeX Font Info:    ... okay on input
line 6. LaTeX Font Info:    Checking defaults for U/cmr/m/n on input
line 6. LaTeX Font Info:    ... okay on input line 6.

(C:\Users\andrew.k\AppData\Roaming\MiKTeX\2.9\tex\context\base\supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
\scratchcounter=\count88 \scratchdimen=\dimen105 \scratchbox=\box26
\nofMPsegments=\count89 \nofMParguments=\count90
\everyMPshowfont=\toks15 \MPscratchCnt=\count91
\MPscratchDim=\dimen106 \MPnumerator=\count92
\makeMPintoPDFobject=\count93 \everyMPtoPDFconversion=\toks16 )
<CQL.pdf, id=1, 722.7pt x 542.025pt> File: CQL.pdf Graphic file (type
pdf)  <use CQL.pdf> Package pdftex.def Info: CQL.pdf used on input
line 9. (pdftex.def)             Requested size: 379.37907pt x
284.52756pt.

Overfull \hbox (34.37907pt too wide) in paragraph at lines 9--10 [][] 
[]

[1 ! pdfTeX error (\pdfsetmatrix): Unrecognized format.. <to be read
again> 
                  \endgroup \set@typeset@protect  l.12 \end{document}


  Here is how much of TeX's memory you used:  1100 strings out of
493921  14605 string characters out of 3144867  62924 words of memory
out of 3000000  4449 multiletter control sequences out of 15000+200000
3640 words of font info for 14 fonts, out of 3000000 for 9000  841
hyphenation exceptions out of 8191  27i,5n,19p,215b,213s stack
positions out of 5000i,500n,10000p,200000b,50000s !  ==> Fatal error
occurred, no output PDF file produced!

Best Answer

Too long for a comment.

Can you try the following example?

\documentclass{article}
\begin{document}
Hello
\pdfsetmatrix{.52495 0 0 .52495}
World
\end{document}

If it breaks, what happens if the \pdfsetmatrix line is replaced by the following?

\pdfsetmatrix{2 0 0 2}

or

\pdfsetmatrix{2.0 0.0 0.0 2.0}

So far I could not reproduce the problem, neither with TL nor MiKTeX.

pdftex.def 2011/05/27 v0.06d, md5sum=3C8A0D99822330F2DFABC0DFB09CE897
graphics.sty 2009/02/05 v1.0o
graphicx.sty 1999/02/16 v1.0f
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (MiKTeX 2.9) (preloaded format=pdflatex 2014.2.18)
CQL.pdf: size=2312 md5sum=8D0D2F67766E6E135B1B70B09BCA5CCA

pdfTeX can calculate MD5 checksums:

\typeout{md5(CQL.pdf)=\pdfmdfivesum file{CQL.pdf}}

As far as I can see, the versions are the same. Also you have output the argument from \pdfsetmatrix (from this answer):

\let\orgpdfsetmatrix\pdfsetmatrix
\renewcommand*{\pdfsetmatrix}[1]{%
  \typeout{* setmatrix: [#1]}%
  \orgpdfsetmatrix{#1}%
}

The output looks correct:

* setmatrix: [.52495 0 0 .52495] 

Thus the only difference I can find is the binary. Are you using the 64bit version? I have tested with the 32bit version of MiKTeX.

Therefore I think, the problem is worth investigating, but difficult, because it seems that it cannot be easily reproduced.


Addition from the comment from Acrofales:

\pdfsetmatrix{2.0 0.0 0.0 2.0} breaks, the variant without dots \pdfsetmatrix{2 0 0 2} works.

From the source code pdftexdir/utils.c:

typedef struct {
    double a;
    double b;
    double c;
    double d;
    double e;
    double f;
} matrix_entry;
...
integer pdfsetmatrix(poolpointer in, scaled cur_h, scaled cur_v)
{
    matrix_entry x, *y, *z;
    char dummy;

    if (page_mode) {
        if (sscanf((const char *) &strpool[in], " %lf %lf %lf %lf %c",
                   &x.a, &x.b, &x.c, &x.d, &dummy) != 4) {
            return 0; /* failure */
        }
    ...
}

The manual page says about %lf:

l: Indicates ... that the conversion will be one of e, f, or g and the next pointer is a pointer to double (rather than float).

Perhaps this is not true for the Compiler MiKTeX uses for its 64bit version, Microsoft Visual C++ 2008 according to the build instructions for Windows. This can also explain the security violations, if the variable sizes do not match for sscanf and memory is written outside the variables.