You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Found by the first CI run of the sanitizer workflow (run, PR #171; meta issue linked as parent). Upstream OBS code, unchanged in this fork.
Report (UBSan, test_rtmp_chunk_size)
plugins/obs-outputs/librtmp/amf.c:59:17: runtime error: left shift of 128 by 24 places cannot be represented in type 'int'
#0 AMF_DecodeInt32 plugins/obs-outputs/librtmp/amf.c:59
#1 HandleChangeChunkSize plugins/obs-outputs/librtmp/rtmp.c:3605
#2 RTMP_ClientPacket plugins/obs-outputs/librtmp/rtmp.c:1317
#3 receive_chunk_size test/cmocka/test_rtmp_chunk_size.c:37
Class
Signed integer overflow (UB) on server-controlled input.
Cause
AMF_DecodeInt32 does (c[0] << 24) | ... with unsigned char *c. c[0] is promoted to int, so any first byte ≥ 0x80 overflows. It decodes every 32-bit field a server sends: chunk size, window ack size, peer bandwidth, AMF numbers' lengths, and so on.
The same pattern is worse at the timestamp sites in rtmp.c (1446, 4879, 5109, 5117, 5364) and AMF_DecodeInt32LE (rtmp.c:3800). These shift elements of char *m_body, and char is signed on x86/ARM Linux. A byte ≥ 0x80 is first sign-extended to a negative int (UB to shift), and on compilers that don't trap it ORs 0xFFFFFF.. into the timestamp.
Reached by
A server (or MITM on plain RTMP) sends a Set Chunk Size, Window Ack or extended-timestamp message with the high bit set in the first byte.
Fix
Cast before shifting: ((uint32_t)c[0] << 24) | ((uint32_t)c[1] << 16) | ..., and (uint32_t)(uint8_t)body[i] << 24 at the rtmp.c sites.
Failing test sketch
test_rtmp_chunk_size already drives this path. Under -fsanitize=undefined -fno-sanitize-recover=undefined it would abort. Adding the per-test UBSan flags it lacks, as test_avc has (and see #159), makes it RED. An extended-timestamp packet with 0x80 in the top byte covers the rtmp.c sites.
Activity
infra: sanitizer triage catches what the first CI run hid
infra: sanitizer triage catches what the first CI run hid
test: Cover RTMP/FLV timestamp decoding with high top bytes
obs-outputs: Decode RTMP/FLV timestamps without signed shifts
infra: sanitizer triage catches what the first CI run hid
test: Cover RTMP/FLV timestamp decoding with high top bytes
obs-outputs: Decode RTMP/FLV timestamps without signed shifts
test: Cover secureToken TEA decoding with a high top byte
obs-outputs: Decode secureToken hex without a signed shift
test: Cover a high byte in the TEA key used for secureToken
obs-outputs: Pack the TEA key without a signed shift
obs-outputs: Pack the TEA key without a signed shift