Repository navigation
obs-outputs: Make DecodeTEA's shifts well-defined - #208
Merged
Merged
Conversation
A connect _result carrying a secureToken reaches DecodeTEA, whose hex decode shifts an int byte by 24. RED under UBSan. Refs obs-rust#173 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01XFvTpgDN6Zh3USjgworNmT
Widen the top byte to uint32_t before shifting by 24 in DecodeTEA, as done for the other obs-rust#173 sites. Values are unchanged. Refs obs-rust#173 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01XFvTpgDN6Zh3USjgworNmT
The configured token is packed into the TEA key with ptr[i] << (n * 8), which shifts an int into the sign bit for bytes >= 0x80. RED under UBSan. Refs obs-rust#173 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01XFvTpgDN6Zh3USjgworNmT
Contributor
Author
|
@zackees, a short note on how we work now, since some of our earlier PRs cost you time. Some of our earlier PRs were unclear, a few went up red, and some were posted before they were ready. That came from our agents posting without enough gating. We've changed the flow:
Each PR from us now ends with a short "How this was tested" section. If you'd rather we did anything differently, tell us and we'll adjust. |
Widen each key byte to uint32_t before shifting in DecodeTEA, matching the hex-unpack fix. Values are unchanged. Refs obs-rust#173 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01XFvTpgDN6Zh3USjgworNmT Local-Gate: v1 tree=8929cc7344900e31f348c1624a0f3662303fff18 secs=123 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791699852,"gate":"rust/all/fmt","host":"linux-x86_64","key":"e05236c8a40b522c388f6ef66eb04e6fcef40af433fcc35e68fc143e38519180","lane":"lint","parents":["1c2b5456089ba937ce9b552965ea30c936860225"],"secs":50,"stamp":"ff6fa3eb4d295fef70f8a8966142512e","tree":"8929cc7344900e31f348c1624a0f3662303fff18","v":1,"via":"run"} Ci-Attestation: {"at":1791699852,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"e05236c8a40b522c388f6ef66eb04e6fcef40af433fcc35e68fc143e38519180","lane":"lint","parents":["1c2b5456089ba937ce9b552965ea30c936860225"],"secs":50,"stamp":"a4f37700690fb2c5598176ef14c82175","tree":"8929cc7344900e31f348c1624a0f3662303fff18","v":1,"via":"run"} Ci-Attestation: {"at":1791699852,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"4fef475e41107961f42cff4729113a9c20bb2f1743b13afdfad3b91183bee815","lane":"rust-test","parents":["1c2b5456089ba937ce9b552965ea30c936860225"],"secs":32,"stamp":"6e4f6809ea264a315f1fc25815d34cee","tree":"8929cc7344900e31f348c1624a0f3662303fff18","v":1,"via":"run"} Ci-Attestation: {"at":1791699852,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"5a69f2850c9c47c48ad95f66c68c9e09bd4ac812cefdc322679988361c2cb974","lane":"tier2-linux","parents":["1c2b5456089ba937ce9b552965ea30c936860225"],"secs":42,"stamp":"17521b8d604685b67c0aeff3ad20c22f","tree":"8929cc7344900e31f348c1624a0f3662303fff18","v":1,"via":"run"}
Member
|
Verified locally, rebased onto master and stamped. The new head is
Thanks for the correction about |
zackees
force-pushed
the
fix/173-tea-shift
branch
from
October 11, 2026 06:24
3ad80e2 to
a8f526d
Compare
3 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A follow-up to #188 for the two remaining #173-pattern shifts, both in
DecodeTEA, and a correction. In #188 I saidrtmp.c:4614only parses a local hex string and is not a server field. That was wrong. It unpacks thesecureTokena server sends in itsconnect_result, so a token byte ≥ 0x80 makes it shift anintinto the sign bit (UB). The TEA key packing just above it has the same pattern for a configured token with a byte ≥ 0x80.Refs #173, #188.
Root cause
plugins/obs-outputs/librtmp/rtmp.c,DecodeTEA(line 4572)::4588key packing:u |= ptr[i] << (n * 8);.ptr[i]is anunsigned charpromoted toint, so<< 24overflows for bytes ≥ 0x80.:4614hex unpack of the server's token:u |= ((HEX2BIN(ptr[6]) << 4) + HEX2BIN(ptr[7])) << 24;. The shifted operand is a whole byte (up to 0xff) held in anint.The
<< 8and<< 16lines can't overflow on OBS's 32-bit-inttargets.Fix
Widen to
uint32_tbefore shifting at both lines, the same pattern #188 used. Two one-line changes. The intended 32-bit bit pattern is unchanged; the cast makes the shift defined.Evidence
Two tests in
test/cmocka/test_amf_decode.cdrive the real path,RTMP_ClientPacket→HandleInvoke→DecodeTEA, with an in-memoryconnect_resultcarrying asecureToken. No server is needed.secure_token_decode_uses_unsigned_shift: the server token has a high top byte. RED at3a1a5979e:rtmp.c:4614:57: runtime error: left shift of 128 by 24 places cannot be represented in type 'int'.secure_token_key_uses_unsigned_shift: the configured token has0x80in a word's top byte. RED at1c2b54560:rtmp.c:4588:21: runtime error: left shift of 128 by 24 places cannot be represented in type 'int'.3ad80e240: 9/9 pass.How this was tested
ENABLE_RUST_LIBOBSOFF and ON, including export parity. The run is pinned to this PR's exact head commit: https://github.com/chriscoveries/obsrust-fork/actions/runs/38117176938Out of scope (separate issue to follow)
DecodeTEAhas two more problems on the same server-reachable path, which this PR doesn't touch::4605rounds the length up to 8-character blocks, and the loop then reads 8 characters per block regardless oftext->av_len, so it reads past the token.n == 0, which leads tov[n - 1]at:4622and a division by zero at:4624.We'll open these as their own issue with options rather than widen this PR.
Compatibility & risk
No API, ABI or wire change.
Status
Ready for review.
Thank you to the obs-rust maintainers and contributors for building this project in the open. In the American spirit of free expression and individual independence, and with the principle of judging contributions on their merit alone, this PR is a small piece of what independent people can build when they come together.