censor/Censor
1
37
Fork
You've already forked Censor
3

bug: incomplete redaction of images or vector drawings? #165

Open
opened 2026年03月20日 12:21:38 +01:00 by mahlzahn · 0 comments

Examples for failing documents

Lines 269 to 279 in 96bd89f
# Possibly failing images redaction for get images counts mismatch
'failing images redaction (#165)': [
'samples_artifex/Bug6901014_CImg_flyer.pdf',
'samples_artifex/Bug6901014_launch_leaflet.pdf',
'samples_artifex/Transparency-DesignGuide.pdf',
'samples_artifex/torture.pdf',
'samples_pymupdf/test_2635.pdf',
'samples_pymupdf/test-3820.pdf',
'samples_pymupdf/test_3950.pdf',
'samples_pymupdf/test_open2.pdf',
],

How to reproduce with PyMuPDF

document = pymupdf.Document("torture.pdf")
page = document[0]
page.add_redact_annot(page.rect, fill=False)
page.apply_redactions(images=pymupdf.PDF_REDACT_IMAGE_REMOVE)
document.save("torture-redacted.pdf", garbage=1)

The created torture-redacted.pdf contains indeed the same 4 images or drawings as the unredacted torture.pdf.

Inconsistently, page.get_images() and page.get_drawings() return no items, but page.get_image_info() returns 4 "images".

Upstream issues

Impact

(削除) Rather high, because user is not even warned because partial image redaction is used. (削除ここまで)

Edit: Likely not that high with !159, because on images count mismatch the user gets at least warned for possibly unredacted images (starting from v0.6.0):

Lines 431 to 452 in 96bd89f
# Check that number of images from different methods matches,
# see https://codeberg.org/censor/Censor/issues/165
if images != pymupdf.PDF_REDACT_IMAGE_NONE:
try:
n_images_get = len(mupdf_page.get_images())
n_images_info = len(mupdf_page.get_image_info())
n_images_blocks = sum(b[-1] == 1 for b in mupdf_page.get_text(
'blocks', flags=pymupdf.TEXT_PRESERVE_IMAGES,
clip=pymupdf.Rect(
pymupdf.FZ_MIN_INF_RECT, pymupdf.FZ_MIN_INF_RECT,
pymupdf.FZ_MAX_INF_RECT, pymupdf.FZ_MAX_INF_RECT)))
if not (n_images_get == n_images_info == n_images_blocks):
print(f'WARNING: Found {n_images_get} image(s) with '
+ f"'pymupdf.Page.get_images()', {n_images_info} image(s)"
+ " with 'pymupdf.Page.get_image_info()' and "
+ f'{n_images_blocks} image(s) with '
+ "'pymupdf.Page.get_text(\"blocks\", "
+ "flags=pymupdf.TEXT_PRESERVE_IMAGES)'")
warnings.append(_(
'Found possibly unredacted images during '
+ 'post-processing on page\xa0{number}'
).format(number=mupdf_page.number + 1))
## Examples for failing documents https://codeberg.org/censor/Censor/src/commit/96bd89f19a24bb2b9d6c8ec89e6546fd730f271f/tests/document_test.py#L269-279 - [samples_artifex/torture.pdf](https://github.com/ArtifexSoftware/tests/blob/master/pdf/torture.pdf) - with embedded vector images, not detected as drawings - [samples_artifex/Bug6901014_launch_leaflet.pdf](https://github.com/ArtifexSoftware/tests/blob/master/pdf/Bug6901014_launch_leaflet.pdf) - with embedded vector images, and with clips, see #134 - [samples_artifex/Transparency-DesignGuide.pdf](https://github.com/ArtifexSoftware/tests/blob/master/pdf/Transparency-DesignGuide.pdf) - ... ## How to reproduce with PyMuPDF ```py document = pymupdf.Document("torture.pdf") page = document[0] page.add_redact_annot(page.rect, fill=False) page.apply_redactions(images=pymupdf.PDF_REDACT_IMAGE_REMOVE) document.save("torture-redacted.pdf", garbage=1) ``` The created `torture-redacted.pdf` contains indeed the same 4 images or drawings as the unredacted `torture.pdf`. Inconsistently, `page.get_images()` and `page.get_drawings()` return no items, but `page.get_image_info()` returns 4 "images". ## Upstream issues - ## Impact ~Rather high, because user is not even warned because partial image redaction is used.~ Edit: Likely not that high with !159, because on images count mismatch the user gets at least warned for possibly unredacted images (starting from v0.6.0): https://codeberg.org/censor/Censor/src/commit/96bd89f19a24bb2b9d6c8ec89e6546fd730f271f/src/pymupdf_helpers.py#L431-452
Sign in to join this conversation.
No Branch/Tag specified
main
v0.7.3
v0.7.2
v0.7.1
v0.7.0
v0.6.0
v0.5.0
v0.4.0
v0.3.0
v0.2.0
v0.1.0
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
censor/Censor#165
Reference in a new issue
censor/Censor
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?