[pdftex] Error when including image with bogus resolution
Max Chernoff
tex at maxchernoff.ca
Fri Jan 17 09:40:28 CET 2025
Hi Karl,
On Thu, 2025-01-16 at 15:20 -0700, Karl Berry wrote:
> +resolution_ratio := 226;
>
> Thanks Max. Seems fine to me (Thanh, any comments?), but how did the
> magic 226 come about?
Look at "added" line before it in the patch :) But this comes from
rearranging
(x * one_inch) / xr >= max_dimen
to prevent any possible overflow and to avoid using floats.
> Regarding the final comment on
> https://tex.stackexchange.com/questions/112911 to ignore the metadata
> entirely, that seems too invasive a change in principle.
Agreed, this would have fairly disastrous backwards compatibility
implications. And besides, this is actually useful sometimes: my scanner
lets me choose the resolution to scan at, so for pages with lots of text
I'll choose a small resolution (small file size) and for images I'll
choose a high resolution (better image quality). In this case, it's good
that pdfTeX parses this metadata so that a low-DPI and a high-DPI
scanned image are both included at the same physical size.
> By the way, I note that LuaTeX gives the similar warning, but then gets
> a TeX error handling your test-1.jpg (didn't try the others). In all
> those lengthy tex.sx exchanges, I got the impression that luatex was
> supposed to be already "fixed" in some way. Evidently not.
>
> $ luatex i.tex # same results with lualatex
> This is LuaTeX, Version 1.18.0 (TeX Live 2024)
> [...]
> warning (file test-1.jpg) (readjpg): unusual resolution of 1dpi by 1dpi
> warning (internal): arithmetic number too big
> warning (internal): arithmetic number too big
> ! Dimension too large.
> ! Dimension too large.
> <recently read> \dimen@
> [...]
>
> $ cat i.tex
> \input graphicx
> \includegraphics{test-1.jpg}
> \end
Partially a graphicx "bug", but the errors are a little clearer if you
just use the primitives:
\input luatex85.sty % Makes LuaTeX act (mostly) like pdfTeX
\pdfximage{test-1.jpg}\pdfrefximage\pdflastximage\eject
\pdfximage{test-2.jpg}\pdfrefximage\pdflastximage\eject
\pdfximage{test-3.jpg}\pdfrefximage\pdflastximage\eject
\pdfximage{test-4.jpg}\pdfrefximage\pdflastximage\eject
\pdfximage{test-5.jpg}\pdfrefximage\pdflastximage\eject
\pdfximage{test-6.jpg}\pdfrefximage\pdflastximage\bye
The problem occurs because LuaTeX rejects (x * 1in / xr) >= MAX_INT, but
not (x * 1in / xr) >= \maxdimen. This only matters when you actually try
and use a too-large dimension, so the following both still work:
\input luatex85.sty
\pdfximage{test-1.jpg}\pdfrefximage width 1in height 1in \pdflastximage\eject
\pdfximage{test-2.jpg}\pdfrefximage width 1in height 1in \pdflastximage\eject
\pdfximage{test-3.jpg}\pdfrefximage width 1in height 1in \pdflastximage\eject
\pdfximage{test-4.jpg}\pdfrefximage width 1in height 1in \pdflastximage\eject
\pdfximage{test-5.jpg}\pdfrefximage width 1in height 1in \pdflastximage\eject
\pdfximage{test-6.jpg}\pdfrefximage width 1in height 1in \pdflastximage\bye
\input luatex85.sty
\pdfximage{test-1.jpg}\rlap{\pdfrefximage\pdflastximage}\eject
\pdfximage{test-2.jpg}\rlap{\pdfrefximage\pdflastximage}\eject
\pdfximage{test-3.jpg}\rlap{\pdfrefximage\pdflastximage}\eject
\pdfximage{test-4.jpg}\rlap{\pdfrefximage\pdflastximage}\eject
\pdfximage{test-5.jpg}\rlap{\pdfrefximage\pdflastximage}\eject
\pdfximage{test-6.jpg}\rlap{\pdfrefximage\pdflastximage}\bye
Actually, the first two images in the second example are missing in the
PDF output, which is probably a LuaTeX bug. I'll send a patch to Luigi
shortly.
Thanks,
-- Max
More information about the pdftex
mailing list.