Commit da531e5
fix: OOB read in tom_render_*_scanline (closes #127)
ASAN on PR #126 surfaced a global-buffer-overflow read 1 byte past
tomRam8 in tom_render_16bpp_cry_scanline (src/tom/tom.c:625).
Same pattern in all five render variants: the per-pixel loop
walks current_line_buffer (= tomRam8[0x1800], 10240 bytes max)
based on tomWidth, which can be set by display registers to a
value larger than the line buffer holds.
Fix: new helper tom_clamp_line_buffer_width() that, given the
current cursor, the requested width, the per-iteration source-byte
cost (2 for 16bpp, 4 for 24bpp), and the pwidth_scale, returns a
clamped width that guarantees the loop won't read past the end of
tomRam8.
Applied to all five render entry points:
- tom_render_16bpp_cry_rgb_mix_scanline
- tom_render_16bpp_cry_scanline (the one ASAN caught)
- tom_render_24bpp_scanline
- tom_render_16bpp_direct_scanline
- tom_render_16bpp_rgb_scanline
Closes #127. With this in, the sanitizers CI job should go fully
clean -- candidate to flip continue-on-error: true to false in a
follow-up.
Co-Authored-By: Claude Opus 4.7 <[email protected]>1 parent c18c2d4 commit da531e5
1 file changed
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
548 | 548 | | |
549 | 549 | | |
550 | 550 | | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
551 | 574 | | |
552 | 575 | | |
553 | 576 | | |
| |||
579 | 602 | | |
580 | 603 | | |
581 | 604 | | |
| 605 | + | |
582 | 606 | | |
583 | 607 | | |
584 | 608 | | |
| |||
620 | 644 | | |
621 | 645 | | |
622 | 646 | | |
| 647 | + | |
623 | 648 | | |
624 | 649 | | |
625 | 650 | | |
| |||
661 | 686 | | |
662 | 687 | | |
663 | 688 | | |
| 689 | + | |
664 | 690 | | |
665 | 691 | | |
666 | 692 | | |
| |||
687 | 713 | | |
688 | 714 | | |
689 | 715 | | |
| 716 | + | |
690 | 717 | | |
691 | 718 | | |
692 | 719 | | |
| |||
729 | 756 | | |
730 | 757 | | |
731 | 758 | | |
| 759 | + | |
732 | 760 | | |
733 | 761 | | |
734 | 762 | | |
| |||
0 commit comments