From 7fe47bac2e801af98e4b4e7673ab75ff87e5f9a8 Mon Sep 17 00:00:00 2001 From: "Jorj X. McKie" Date: Tue, 3 Oct 2023 12:35:07 -0400 Subject: [PATCH 1/3] Fix #2596 When continuing to use a page object after the PDF has been saved with garbage options may change the MuPDF cache such that e.g. rendering the page after the save will produce wrong appearance or even garbled appearance. The user needs to reload the page (page = doc.reload(page)) before using it further, especially for rendering. The reload method now always empties the cache. --- fitz/fitz.i | 1 + src/__init__.py | 1 + tests/test_general.py | 14 ++++++++++++++ 3 files changed, 16 insertions(+) diff --git a/fitz/fitz.i b/fitz/fitz.i index 10773f573..5b464361f 100644 --- a/fitz/fitz.i +++ b/fitz/fitz.i @@ -4625,6 +4625,7 @@ if basestate: old_annots[k] = v page._erase() # remove the page page = None + TOOLS.store_shrink(100) page = self.load_page(pno) # reload the page # copy annot refs over to the new dictionary diff --git a/src/__init__.py b/src/__init__.py index 8cb815d93..2c8c13b6b 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -5042,6 +5042,7 @@ def reload_page(self, page: "struct Page *") -> "struct Page *": old_annots[k] = v page._erase() # remove the page page = None + TOOLS.store_shrink(100) page = self.load_page(pno) # reload the page # copy annot refs over to the new dictionary diff --git a/tests/test_general.py b/tests/test_general.py index e7dcdb517..b007b2306 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -539,3 +539,17 @@ def test_2692(): clip=fitz.Rect(0,0,10,10), ) + +def test_2596(): + """Cconfirm correctly abandoning cache when reloading a page.""" + doc = fitz.Document("resources/test_2596.pdf") + page = doc[0] + pix0 = page.get_pixmap() # render the page + _ = doc.tobytes(garbage=3) # save with garbage collection + + # Note this will invalidate cache content for this page. + # Reloading the page now empties the cache, so rendering + # will deliver the same pixmap + page = doc.reload_page(page) + pix1 = page.get_pixmap() + assert pix1.samples == pix0.samples From 885f75c4f85f7ae5d87342c0f31c4c74f0c15df1 Mon Sep 17 00:00:00 2001 From: "Jorj X. McKie" Date: Tue, 3 Oct 2023 12:41:04 -0400 Subject: [PATCH 2/3] add missing testfile --- tests/resources/test_2596.pdf | Bin 0 -> 34555 bytes tests/test_general.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 tests/resources/test_2596.pdf diff --git a/tests/resources/test_2596.pdf b/tests/resources/test_2596.pdf new file mode 100644 index 0000000000000000000000000000000000000000..96498a0fc1b4b1d4cdaf8474102c0dca72fd94de GIT binary patch literal 34555 zcmeIb2b>et_c#i;2&{A|Qq+Kez`|x`GLs^R%%mrq-UEo~J=sm!B&+l$2(mO06ln{x zD4>FZAS#F=MGyoL3y6q-f)!9i^qooBE`Gni_xrs6`@ClscIVEVd+%xY-gD16chX-i z5Di6(S%v*~zq`;T_U?QXIQ5fg@djfx@-7c<@YD94r9K`H~&R5F4uUT$8_&B zvqv#SL0jA5V`?}|%Z7f;#cFPGYbnTx(yX%kU5;A5OG6-AW{x;sUE(mDg=Bez zWItSxtP`llcr2#G<@0#s3=H8gDPKIMc18J-P-!IW0;S-Bas(q$U8&9C8pV``ovxJ2 z$rQNCeGZpaOffKmV9<=!j;Y7JWr4+02DY7^@G#ezzf1i3*I!4EKd`J*+kV0i*S&H6 z;0)gL-5%@ty;L&4pLF#lS>Jx6J9Q?r|GG&gJa+T?i7{7x?cQAb%CU#eE`R@L>Z!Rq z)-6n5efHsDsC34{ehJ;@tv(zTdd`AetQ6cgcjJ%f;2pF5(xectz7*&^Um}?B*7Vo( zqs}~~|KgL`?nS)YtG93M@j;7cK4(_Ff1!UH_3x9q^ceR7!k;yJ{Fd(*zu9NzR~Oc! zM`s;vI|#F`-|*_|zqYM@VEe;wR3+t1$&pI@T(hb_F38Gsqc$-foUyv-UFDpkMT*L$ zt6$ioS{9bB8n#{bhu+w;pFB`BBXFRk`UGRidw;!l;Dt+{?!R&9rK9SnN`1dGKmT<4 zAJwYi%iKKn4b98;2Ai$Qt)g)%eX0f0RW2ICY@S+AYr(+{KXo za((~R0_CJx!sne6kBw5UEWW=q73n?(Yg_$>c|4ib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=C8-D%)Yi{>E`_& z`Qdqox<301Z+UY3&(wRq)&d2xcc^H=jDY;mJ2!jywPRm>bMf z*S3#4_vBy8dfoQK?Z1Ct{N|&7J^cBD7ss8td8Ac!hld|JSi!yNz3I4gcGdlbs=?2# ze`v$a=v(my@!{FmXMa)g z@|AagJTQClM`x$KHR#XReqD6rh2`UuH+FjL`}X`8IP%?+hh(SLy~+Fi<7=Vw&I@0E zl=S_u_W4<-UU>7NYm;uSyy3XAcizQIs^3(Lmd|-8`B(pOvG&Ybk zHg4W9<&$8w=F+-r&EZ;8H?vvE1OL~%5S%`%^8d?SNQUw}-$zhBhNF{thCj-O8 zJY@7Bh6YZv#VZ)#!_RzSNh&^sL6(-nHm%;I$(S;NSpa!}H@Tctd3)I2N}N&hU-5^f$B6ANovr?J;Qxzz7)s$)RWt z$zst*r{P_w6o<#7_(Fuw65u?n#~+b7d|7+e8bW9E0c@O0@4;NH)8E6(%AK74zW`QAbm0I1 literal 0 HcmV?d00001 diff --git a/tests/test_general.py b/tests/test_general.py index b007b2306..9e78b17e5 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -542,7 +542,7 @@ def test_2692(): def test_2596(): """Cconfirm correctly abandoning cache when reloading a page.""" - doc = fitz.Document("resources/test_2596.pdf") + doc = fitz.Document(f"{scriptdir}/resources/test_2596.pdf") page = doc[0] pix0 = page.get_pixmap() # render the page _ = doc.tobytes(garbage=3) # save with garbage collection From 6b7e54b5f40a6c6cc97ca38659575e73fe1f891a Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Wed, 4 Oct 2023 22:50:59 +0100 Subject: [PATCH 3/3] src/__init__.py: address #2596 in rebased. The underlying fz_page was being kept alive so reload_page()'s call of fz_load_page() was returning it from the document's internal list of pages instead of regenerating it. --- src/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/__init__.py b/src/__init__.py index 2c8c13b6b..75ff1a8fa 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -5040,6 +5040,20 @@ def reload_page(self, page: "struct Page *") -> "struct Page *": pno = page.number # save the page number for k, v in page._annot_refs.items(): # save the annot dictionary old_annots[k] = v + + # We need to set `page.this` to `None` here in order to force the + # `mupdf::FzPage` to be removed from the MuPDF document's internal + # list, so that when `self.load_page()` is called below, its call of + # `fz_load_page()` will create a new `mupdf::FzPage`. + # + # This only works if the MuPDF `fz_page`'s reference count is 1. User + # code will have to work fairly hard to break this, by somehow making + # a copy of the mupdf::FzPage itself; for example making a copy in + # Python will usually create a new Python object that refers to the + # same mupdf::FzPage and this not increment the MuPDF reference count. + # + assert page.this.m_internal.refs == 1 + page.this = None page._erase() # remove the page page = None TOOLS.store_shrink(100)