If you write your own parser for PDF inline images, the table that expands /W, /H, /CS and /F is not optional. In this run, deleting one entry, F to Filter, was enough to make a 20-line parser read to the end of the content stream and treat the closing EI, a Q operator and the next line of text as pixel data.

The samples are T1 to T4, four tiny hand-written PDFs made for this experiment. The only photo sits in T1: a crop of "Lake Mountain Landscape" by Bonnie Moreland, from Wikimedia Commons (CC0). No other third-party material is used. Everything ran on a single Apple-silicon Mac, one pass per method. The parser is a demo built for the experiment, not a library.

What an inline image looks like to a parser

An XObject image is a separate PDF object: the content stream refers to it by name, as in /Im1 Do, and the pixels live elsewhere. An inline image keeps everything in the stream. BI opens it, a dictionary follows, ID flags the start of the data and EI closes it. The dictionary uses short keys (/BPC, /CS, /W, /H, /F, /DP, /D, /IM, /I), and some values are shortened too (/G, /RGB, /Fl).

A parser then has to decide where the data stops. The demo has two branches. With a filter the data length is unknown, so it searches for EI. Without one the length is width × height × components × bits per component / 8. Which branch runs depends on one entry, /F.

The core of the parser

This is an excerpt of the 20-line script: printing and the zlib check are removed, the comments are translated, and ... marks a cut. The branch on 'Filter' in d is the part that matters.

ABBR = {'W': 'Width', 'H': 'Height', 'BPC': 'BitsPerComponent', 'CS': 'ColorSpace', 'DP': 'DecodeParms', 'D': 'Decode', 'F': 'Filter', 'IM': 'ImageMask', 'I': 'Interpolate'} ... d = {abbr.get(k.decode()[1:], k.decode()[1:]): v.decode().lstrip('/') for k, v in zip(t[0::2], t[1::2])} start = idp + 3 if 'Filter' in d: # compressed: length unknown, find EI end = s.find(b'\nEI', start) else: # uncompressed: width x height x components x bpc / 8 end = start + int(d['Width']) * ... // 8 

The second run removes the F entry. The unknown key falls through abbr.get unchanged, so the dictionary holds 'F': 'Fl' and no 'Filter'.

Measured, both runs in one table

T1 has two inline images: an 8×8 grayscale one with no filter and a 16×16 RGB one with /F /Fl. The script prints one block per image per run. The table below is a reformatted excerpt of that output (dictionaries shortened to key names), and every one of the four blocks is a row.

Run Image dictionary Bytes taken Inflated / needed Last bytes of the data What follows
Correct table W 8, H 8, BPC 8, CS G 64 64 / 64 `b'\x90\xb0\xd0\xf0\x144Tt\x94\xb4\xd4\xf4\x188Xx\x98\xb8\xd8\xf8\x1c<\\ \x9c\xbc\xdc\xfc'`
Correct table W 16, H 16, BPC 8, CS RGB, Filter Fl 46 768 / 768 b'qi!I=~\xc5\x98Z\x06\x9bzZ\x87\x0f\x19\xf1EFz\xa0\x05\x00\x00\x19\x1f:o' b'\nEI\nQ\nBT /F1 9 Tf '
F not mapped W 8, H 8, BPC 8, CS G 64 64 / 64 same as above b'\nEI\nQ\nBT /F1 9 Tf '
F not mapped W 16, H 16, BPC 8, CS RGB, F Fl 102 102 / 768 b'(inline 16x16 /F /Fl) Tj ET\n' b''

The grayscale image is unaffected, because it has no filter and its length comes from the arithmetic. Only the compressed one breaks. With the F entry missing, the parser believes the data is raw, wants 768 bytes, and keeps reading to the end of the stream. It returns 102 bytes, and the printed tail of those bytes is the caption text. Set against the correct run, where EI, Q and BT /F1 9 Tf follow the data, the EI, the Q and the next text line were all consumed as pixels. Nothing was inflated in that run, so its "inflated" figure just repeats the byte count.

Correct abbreviation table versus F not mapped, side by side

Look at the right-hand column of the figure: the red "102 of 768 needed" and the highlighted last bytes are caption text, not image data.

Inferred, not measured

Nothing in this paragraph was printed by the script; it is inference. T1 is tiny, so the end of the stream arrives after 102 bytes. On a page with more content after the image, the same missing entry would plausibly make the parser take a full 768 bytes, mixing the real data with whatever operators follow, and resume parsing from the middle of the content stream. In the T1 run no exception is raised, and the only sign is the 102-against-768 mismatch in the printout. A check that the bytes after the data start with EI would likely catch it, but that check is a suggestion and was not part of this run.

Measured, the mature libraries did not trip

On T1 to T4, poppler's pdfimages, PyMuPDF and pypdf (6.10 in this run) did not misread an abbreviated key. T4 hides the bytes " EI " at bytes 20 to 23 of an 8×8 grayscale image, a trap for parsers that search for EI. None of the three was fooled, and neither was ImgIng, the browser tool covered at the end of this section. The likely reason (inference) is that uncompressed data is cut by the width × height arithmetic instead of by a search.

Listing is a separate matter. On T1, PyMuPDF's get_images() reported 1 image where pdfimages -list reported 3; the likely reason (inference) is that it walks only the XObject resources. On T2, pypdf 6.10 returned the page's five inline images twice and left out the one nested in the Form XObject.

ImgIng ( https://imging.ai/ ) is the option when you only need the files and not a parser; it runs in a desktop browser. On these four PDFs the plain inline images were exported. T2's inline JPEG, 903 bytes in the stream, came out with identical bytes, and the eight icons repeated on both pages of T3 came out once, labelled with both page numbers, nine results in total. Its internals were not examined.

Checks worth adding

If you do write the parser, take the complete abbreviation table from the PDF specification rather than only the keys you happen to see, add a check for EI after the data, and test on a file that has a filter.