Skip to content

pdftoraster: extract copy_image_rows() helper and add an ASan regression test - #206

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
rkt0209:test-pdftoraster-real-fn
Aug 9, 2026
Merged

pdftoraster: extract copy_image_rows() helper and add an ASan regression test#206
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
rkt0209:test-pdftoraster-real-fn

Conversation

@rkt0209

@rkt0209 rkt0209 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Follow-up to the review on #204: the standalone test-pdftoraster-copy-height.c re-implemented the copy loop, so it would pass even if the real write_page_image() regressed. This makes the test drive the real library code.

Refactor (no behaviour change): the copy loop in write_page_image() is extracted into a static void copy_image_rows(...) that write_page_image() now calls. The loop body is unchanged (existing filter tests still pass).

Test: test-pdftoraster-copy-height.c #includes the in-tree cupsfilters/pdftoraster.c to reach the static helper and its types, then calls copy_image_rows() under AddressSanitizer with a colordata buffer sized to exactly copy_height rows while cupsHeight is one row taller — the "rendered image shorter than page" case where the off-by-one lived. The buggy h <= copy_height reads one row past the buffer and ASan aborts; the fixed h < copy_height stays in bounds. Deterministic, no pdftoppm needed.

The .sh wrapper builds it under ASan and skips (Automake exit 77) when ASan is unavailable; the .c is listed in EXTRA_DIST so it ships in make dist.

Verified: fixed code PASS, buggy code FAIL (ASan heap-buffer-overflow in copy_image_rows), across system-2x / source-2.5.x / source-3.x.

@rkt0209
rkt0209 force-pushed the test-pdftoraster-real-fn branch from 782c261 to 186ea1e Compare August 9, 2026 11:31
@tillkamppeter
tillkamppeter merged commit 1573146 into OpenPrinting:master Aug 9, 2026
15 checks passed
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.

2 participants