Skip to content

command: fix signed integer overflow in overlay-add#18144

Open
Melodictreacle wants to merge 1 commit into
mpv-player:masterfrom
Melodictreacle:fix-overlay-add-overflow
Open

command: fix signed integer overflow in overlay-add#18144
Melodictreacle wants to merge 1 commit into
mpv-player:masterfrom
Melodictreacle:fix-overlay-add-overflow

Conversation

@Melodictreacle

@Melodictreacle Melodictreacle commented Jun 16, 2026

Copy link
Copy Markdown

Fixes #18128.
cmd_overlay_add computed w * 4 in int arithmetic during parameter validation. A large positive w (e.g. 1073741824) passes the w <= 0 check but overflows int when computing w * 4 — undefined behavior, caught by UBSan. This adds a w > INT_MAX / 4 guard before the stride < w * 4 comparison so the multiplication can't overflow; oversized widths now take the existing "inconsistent parameters" error path.
Testing: Built with -Db_sanitize=address,undefined and ran the repro from the issue. Before: UBSan reports signed integer overflow: 1073741824 * 4 cannot be represented in type 'int' at command.c:5434 and aborts. After: mpv prints overlay-add: inconsistent parameters and exits cleanly.

w is an int and w * 4 was computed in int arithmetic during parameter
validation. A large positive w (e.g. 1073741824) passed the w <= 0
check but overflowed when computing w * 4, which is undefined behavior
and was reported by UBSan. Reject w > INT_MAX / 4 before the
multiplication.

Fixes mpv-player#18128
@llyyr

llyyr commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Could you tell us what told you to contribute to mpv? Is mpv listed in some bounty program or Hacktoberfest-esque program?

@Melodictreacle

Copy link
Copy Markdown
Author

i was trying to find an issue which was easier to solve , i am a beginner i found this issue basic , my bad if i did anything wrong , sorry

@llyyr

llyyr commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

mpv just got a large influx of AI slop (like yours) today so I was curious if it was a coincidence or not. I haven't actually reviewed the changes to tell if it's the right fix or not in this case

@Melodictreacle

Copy link
Copy Markdown
Author

i just wrote the commit message with AI , my bad , not gonna try to justify

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.

UBSan error signed integer overflow: 1073741824 * 4 cannot be represented in type 'int' in cmd_overlay_add

2 participants