libimg/png: fix page fault when unpacked image data ends at page boundary #568

Merged
Burer merged 2 commits from libimg-png-fix into main 2026-07-18 10:54:26 +00:00
Owner

KIV were crashing on the attached files. Now this is fixed.

KIV were crashing on the attached files. Now this is fixed.
Leency requested review from dunkaist 2026-07-11 13:58:50 +00:00
Leency requested review from IgorA 2026-07-11 13:58:50 +00:00
Burer changed title from libimg: fix png.asm page fault on 4096px-tall images (buffer over-read at page boundary) to libimg/png: fix page fault when unpacked image data ends at page boundary 2026-07-11 17:54:50 +00:00
Burer approved these changes 2026-07-11 17:55:19 +00:00
@@ -931,3 +929,1 @@
mov ecx, ebx
.rgb2.innloop2:
mov eax, [esi]
; do not read a whole dword: the last pixel of the unpacked data may end
Owner

I'm not familiar with the internals of PNG, but is it possible that two or three last bytes are unmapped?

I'm not familiar with the internals of PNG, but is it possible that two or three last bytes are unmapped?
Owner

I believe, no.
The three bytes read are the pixel's own R, G, B - the loop advances esi by 3 per pixel, so [esi+2] is the last valid byte and only [esi+3] was past the buffer.
Data the decompressor just wrote cannot be unmapped, so reading exactly as many bytes as the pixel occupies is always safe.

I believe, no. The three bytes read are the pixel's own R, G, B - the loop advances `esi` by 3 per pixel, so `[esi+2]` is the last valid byte and only `[esi+3]` was past the buffer. Data the decompressor just wrote cannot be unmapped, so reading exactly as many bytes as the pixel occupies is always safe.
dunkaist marked this conversation as resolved
IgorA approved these changes 2026-07-15 15:08:04 +00:00
Burer added 2 commits 2026-07-18 10:45:44 +00:00
libs/libimg: more performant fix
Test PR / Build (ru_RU) (pull_request) Successful in 1m52s
Test PR / Build (en_US) (pull_request) Successful in 1m57s
Test PR / Build (es_ES) (pull_request) Successful in 2m0s
c2e9bcbf8e
Burer force-pushed libimg-png-fix from 880fcf3bf5 to c2e9bcbf8e 2026-07-18 10:45:44 +00:00 Compare
Burer merged commit 3922240df3 into main 2026-07-18 10:54:26 +00:00
Burer deleted branch libimg-png-fix 2026-07-18 10:54:26 +00:00
Sign in to join this conversation.
No Reviewers
No labels
4 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: KolibriOS/kolibrios#568