Skip to content

ntsc filter: clamp the left-edge taps with signed arithmetic - #19765

Merged
LibretroAdmin merged 1 commit into
libretro:masterfrom
milnet01:pr/ntsc-left-edge-taps
Oct 9, 2026
Merged

LibretroAdmin merged 1 commit into
libretro:masterfrom
milnet01:pr/ntsc-left-edge-taps

Conversation

@milnet01

@milnet01 milnet01 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

ntsc_process_line clamped each chroma tap with x + t < 0, but x is unsigned, so the test never fired. At the left edge x + t wrapped, the upper clamp took it to the last sample of the line, and the right edge's colour bled onto the left edge of every scanline. The wrapped sum also gave those taps the wrong phase whenever the phase count does not divide 2^32, which the default 12 does not.

The tap position is now a signed int, clamped, and a negative phase is folded back into range.

Testing: an ASan+UBSan harness that runs ntsc_create and ntsc_packets on one line, black but for four white pixels on the right. Before: the left-most six output pixels are purple and blue. After: all black, right edge unchanged. Without the phase fold, UBSan reports index -6 into lut_cos. ntsc.so built with gfx/video_filters/Makefile; -Wall -Wsign-compare gives no warnings, against 2 before.

Found by a static-analysis pass over the tree.

🤖 Generated with Claude Code

ntsc_process_line clamped each chroma tap with "x + t < 0", but x is
unsigned, so the test never fired. At the left edge x + t wrapped, the
upper clamp took it to the last sample of the line, and the right
edge's colour bled onto the left edge of every scanline. The wrapped
sum also gave those taps the wrong phase whenever the phase count does
not divide 2^32, which the default 12 does not. Take the tap position
as a signed int, clamp it, and fold a negative phase back into range.

Tests: an ASan+UBSan harness that runs ntsc_create and ntsc_packets on
one line, black but for four white pixels on the right. Before: the
left-most six output pixels are purple and blue. After: all black,
right edge unchanged. Without the phase fold, UBSan reports index -6
into lut_cos. ntsc.so builds with -Wall -Wsign-compare and no
warnings, against 2 before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LibretroAdmin
LibretroAdmin merged commit da111da into libretro:master Oct 9, 2026
114 of 115 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