diff --git a/docs/embedpdf/fork-ledger.md b/docs/embedpdf/fork-ledger.md index 2635fb7b5..9a9868fd7 100644 --- a/docs/embedpdf/fork-ledger.md +++ b/docs/embedpdf/fork-ledger.md @@ -118,10 +118,12 @@ saved. edits, and the copy happens outside any transaction. On a frozen base it writes shared state. **Where.** Const walks in the content parser, `cpdf_interactiveform.cpp`, `cpdf_nametree.cpp` (`CreateForReading`), `cpdf_linklist.cpp` and `cpdf_annotlist.cpp`; in-memory appearances in -`cpdf_annot.cpp`. Writes that read first: the field pruning in `fpdf_flatten.cpp` compares fields -read const and takes an array mutable only when an entry goes. +`cpdf_annot.cpp`, and where one draws (`EPDFAnnot_GetDrawingRect` in `epdf_annot.cpp`). Writes +that read first: the field pruning in `fpdf_flatten.cpp` compares fields read const and takes an +array mutable only when an entry goes. **Guarded by.** `cpdf_read_only_graph_guard_unittest.cpp`, `EPDFAnnotEmbedderTest.DrawingARedactionMarkWithoutAppearanceWritesNone`, +`EPDFAnnotEmbedderTest.AskingWhereAMarkDrawsLeavesALayerAlone`, `EPDFStampResizeEmbedderTest.ADrawingFromALayersPageLeavesTheLayerAlone`; layer mode's list of tests that write (`testing/embedpdf_layer_mode_writers.txt`): a test that only reads must leave nothing in a layer. diff --git a/fpdfsdk/epdf_annot.cpp b/fpdfsdk/epdf_annot.cpp index 175f2464b..27c4daed9 100644 --- a/fpdfsdk/epdf_annot.cpp +++ b/fpdfsdk/epdf_annot.cpp @@ -4537,13 +4537,15 @@ EPDFAnnot_GetDrawingRect(FPDF_ANNOTATION annot, if (!context || !rect) { return false; } - RetainPtr dict = context->GetMutableAnnotDict(); + const CPDF_Dictionary* dict = context->GetAnnotDict(); CPDF_Document* doc = context->GetPage()->GetDocument(); if (!dict || !doc) { return false; } - // Generating only when drawn: asking where it draws writes nothing. - CPDF_Annot drawn(std::move(dict), doc, + // Generating only when drawn, from a dictionary read as a render reads it: + // asking where it draws writes nothing. Taken for writing, the dictionary + // would be copied into a layer. + CPDF_Annot drawn(pdfium::WrapRetain(const_cast(dict)), doc, CPDF_Annot::MissingAppearance::kGenerateWhenDrawn); std::optional box = drawn.GetDrawingRect( static_cast(appearanceMode)); diff --git a/fpdfsdk/epdf_annot_embeddertest.cpp b/fpdfsdk/epdf_annot_embeddertest.cpp index 8bd5ec5a5..f23e06acd 100644 --- a/fpdfsdk/epdf_annot_embeddertest.cpp +++ b/fpdfsdk/epdf_annot_embeddertest.cpp @@ -1364,6 +1364,35 @@ TEST_F(EPDFAnnotEmbedderTest, DrawingARedactionMarkWithoutAppearanceWritesNone) EPDF_ReleaseBaseDocument(base); } +// Asking where a mark without an appearance draws (redact_annot.pdf) only +// reads it: on a layer the mark's dictionary is not copied in, so the layer +// holds as little afterwards as before. +TEST_F(EPDFAnnotEmbedderTest, AskingWhereAMarkDrawsLeavesALayerAlone) { + FileAccessForTesting base_access("redact_annot.pdf"); + EPDF_BASE_DOCUMENT base = EPDF_LoadBaseDocument(&base_access, nullptr); + ASSERT_TRUE(base); + { + ScopedFPDFDocument layer( + EPDFLayer_OpenLayer(base, nullptr, nullptr, nullptr)); + ASSERT_TRUE(layer); + ScopedFPDFPage page(FPDF_LoadPage(layer.get(), 0)); + ASSERT_TRUE(page); + ScopedFPDFAnnotation mark(FPDFPage_GetAnnot(page.get(), 0)); + ASSERT_EQ(FPDF_ANNOT_REDACT, FPDFAnnot_GetSubtype(mark.get())); + ASSERT_FALSE(FPDFAnnot_HasKey(mark.get(), "AP")); + ASSERT_EQ(0u, EPDFLayer_GetPromotedObjectCount(layer.get())); + + FS_RECTF drawn = {}; + ASSERT_TRUE(EPDFAnnot_GetDrawingRect( + mark.get(), FPDF_ANNOT_APPEARANCEMODE_NORMAL, &drawn)); + EXPECT_GT(drawn.right, drawn.left); + EXPECT_GT(drawn.top, drawn.bottom); + EXPECT_FALSE(FPDFAnnot_HasKey(mark.get(), "AP")); + EXPECT_EQ(0u, EPDFLayer_GetPromotedObjectCount(layer.get())); + } + EPDF_ReleaseBaseDocument(base); +} + TEST_F(EPDFAnnotEmbedderTest, DrawingRectIsWhereTheAppearanceIsDrawn) { embedpdf_test::ScopedTestDocument doc(NewTestDocument()); ASSERT_TRUE(doc);