Skip to content

Read an annotation's dictionary const when asking where it draws - #136

Merged
bobsingor merged 1 commit into
embedpdf/mainfrom
embedpdf/fix/drawing-rect-reads-const
Nov 29, 2026
Merged

bobsingor merged 1 commit into
embedpdf/mainfrom
embedpdf/fix/drawing-rect-reads-const

Conversation

@bobsingor

Copy link
Copy Markdown
Contributor

Cause

EPDFAnnot_GetDrawingRect() took the annotation's dictionary with GetMutableAnnotDict() to build the CPDF_Annot it asks. The call only reads: a missing appearance is drawn in memory (MissingAppearance::kGenerateWhenDrawn) and nothing is written. But on a layer a dictionary taken for writing is copied in, and here outside any transaction, against reads-dont-write.

The engine asks where an annotation or a widget without a stored appearance draws before it renders it. So the first render of a page left a copy of each such annotation of the file in the layer.

What that broke: the engine tells whether a page changed by what the layer holds of it. A page is deleted, the delete is undone, the page is rendered for the first time, and the redo of the delete finds a page that reads as changed and leaves it. It shows when nothing drew the page before the delete in the same layer session, which is every time through the server. It is in the released runtime too.

A render (fpdf_view.cpp) and the flattener (epdf_flatten.cpp) read the same dictionary const for the same drawing. This was the one reader that didn't.

Change

  • EPDFAnnot_GetDrawingRect() reads the dictionary const, as those two do.
  • The ledger's reads-dont-write rule names the function and its guard.

I went through every exported function of fpdfsdk/epdf_*.cpp whose name reads (Get, Has, Is, Count, Render, Export and the like) for a GetMutable* call in its own body. Besides this one, EPDFAnnot_ExportAppearance() and EPDFPage_ExportAnnotationsAsDocument() have one, on the copy they build and not on the source. A mutable getter behind a helper is not covered by that search.

Tests

  • EPDFAnnotEmbedderTest.AskingWhereAMarkDrawsLeavesALayerAlone: on a layer over redact_annot.pdf, asking where the mark without an appearance draws gives its box and leaves the layer holding nothing.
  • It leaves nothing in a layer, so the list of layer-mode writers is unchanged. No listed count moved.

Checked

  • Without the change the test fails: the layer holds one object after the call.
  • macOS: unit 1412 passed. Embedder 1885 passed and 12 failed, the 12 golden failures an unchanged build of the base has, by name.
  • Linux x64, in the release image: unit 1419 passed, embedder 1899 passed, none failed.
  • The whole suite in layer mode, on macOS and on Linux: no error, and every count as the list gives it.
  • Pixel runner on macOS: the same failures and surprises as on the base build.
  • check-fork-tags.py --strict, check-c-api.py (604 functions). check-globals.py on a macOS library built from this branch merged with Give every redrawn form field a new appearance stream #135.
  • WebAssembly and a macOS library built from this branch merged with Give every redrawn form field a new appearance stream #135, in the engine at the current pin:
    • Delete a page, undo, read the page's drawings for the first time, redo: the redo deletes the page, in the local engine and through the server. With Give every redrawn form field a new appearance stream #135 alone it is left alone in both.
    • The local engine's suite passes (2279 tests), and the cloud engine's through the server (1395).

Left

EPDFAnnot_GetDrawingRect() took the annotation's dictionary with
GetMutableAnnotDict() to build the CPDF_Annot it asks. On a layer that
copies the dictionary in, outside any transaction, though the call only
reads: an appearance that is missing is drawn in memory, and nothing is
written.

The engine asks where an annotation or a widget without a stored
appearance draws before it renders it. So the first render of a page left
a copy of each such annotation of the file in the layer. The engine tells
whether a page changed by what the layer holds of it: after a page's
delete was undone and the page was rendered for the first time, it took
the page for a changed one and left the redo of the delete alone.

The dictionary is now read const, as a render (fpdf_view.cpp) and the
flattener read it for the same drawing.

Test: EPDFAnnotEmbedderTest.AskingWhereAMarkDrawsLeavesALayerAlone. It
fails without the change: the layer holds one object after the call. It
leaves nothing in a layer, so the list of layer-mode writers stays as it
is.
@bobsingor
bobsingor merged commit d152cc8 into embedpdf/main Nov 29, 2026
1 check passed
@bobsingor
bobsingor deleted the embedpdf/fix/drawing-rect-reads-const branch November 29, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant