Skip to content

fix(mjpeg): correct dimension clamping and add EOI bounds guard#2190

Open
MechanicalCoderX wants to merge 1 commit intoAlexxIT:masterfrom
MechanicalCoderX:fix/mjpeg-dimension-clamping
Open

fix(mjpeg): correct dimension clamping and add EOI bounds guard#2190
MechanicalCoderX wants to merge 1 commit intoAlexxIT:masterfrom
MechanicalCoderX:fix/mjpeg-dimension-clamping

Conversation

@MechanicalCoderX
Copy link
Copy Markdown

w &= 3 and h &= 3 kept only the low 2 bits instead of rounding down to the nearest multiple of 4. A 1921-pixel-wide frame would be encoded with width=1 rather than width=1920, producing a corrupt RTP packet. The correct operator is &^= 3 (bit-clear).

Also guard the JPEG EOI check with len(buf) >= 2 before indexing the last two bytes, preventing a panic on a malformed or empty frame.

w &= 3 and h &= 3 kept only the low 2 bits instead of rounding down
to the nearest multiple of 4.  For example, a 1921-pixel-wide frame
would be encoded with width=1 rather than width=1920, producing a
corrupt or zero-size RTP packet.  The correct operator is &^= 3
(bit-clear), which zeroes the low two bits.

Also guard the JPEG EOI check with len(buf) >= 2 before indexing the
last two bytes, preventing a panic on a malformed/empty frame.
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.

1 participant