feat(libwebrtc): implement RtpPacket::Parse #20036
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20036"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Krille2004zzz on 2026-11-14T12:55:54Z.
What
libwebrtc
webrtc::RtpPacket::Parse(const uint8_t*, size_t)(_ZN6webrtc9RtpPacket5ParseEPKhm) threwnot implemented. This PR ports it from M134 (8d78f5de)rtp_packet.cc(Parse,ParseBuffer,Clear,FindOrCreateExtensionInfo), with theCopyOnWriteBuffer::SetData/SetSize/MutableDataandBuffer::SetDatapaths fromcopy_on_write_buffer.handbuffer.h. The newsrc/RtpPacket.cppstarts with their notices. At M127 (e0b28a6a) the parser is identical.Layout: Clang 19 + libc++ probes of the real M134 headers give a 112-byte, non-polymorphic object: header fields at 0–15,
payload_offset_at 16,payload_size_at 24,RtpHeaderExtensionMapat 32 (23 bytes), theExtensionInfovector at 56,extensions_size_at 80 andrtc::CopyOnWriteBufferat 88. M127's map is one byte shorter, which moves nothing. Like #20031, this assumes the module's standard library is libc++.Parse: follows upstream's release behaviour:
ParseBufferclears the packet (fields reset, extension entries emptied with capacity kept, buffer unshared and reset to the 12-byte0x80header);0xBEDE) and two-byte (0x100x) extensions with padding, duplicate IDs overwritten, reserved ID 15 stopping the scan, and oversized lengths or offsets past 16 bits stopping it; other profiles are skipped;The extension-entry vector grows like libc++ through guest
operator new/delete. Release logs and DCHECKs are omitted. A null packet or a null buffer of 12 or more bytes throws, and so does clearing after a failed parse when the packet has no buffer or one under 12 bytes, where release upstream would write out of bounds.Debt: the stub is removed, the libwebrtc unknown-export count drops from 222 to 221, and a debt entry records the layout and that the console's ABI and behaviour are unverified.
Tested
guest_webrtc_rtp_packet_header,_extensionsand_buffer(core/libs/prx/libwebrtc/tests/RtpPacket.cpp) cover:Parse/ParseBuffer/Clearandcopy_on_write_buffer.cc, built from the real M134 sources with Clang 19 + libc++, and this implementation gave identical results on the same 200,000 generated packets (60,625 valid, 23,223 with extensions, 12,220 with padding, buffers shared at intervals): every field, every extension entry, and the buffer's size, capacity, reference count and bytes. Reading the real objects through the new structs matched every field.<=instead of<fails two tests; growing the buffer 2× instead of 1.5× fails the buffer test.ctest -R '[Ww]eb[Rr]tc|[Nn]ack|[Rr]tp|public_headers|export_gap|conventions|progress_report|test_registration|debt': 247/247 passed. Not tested on a console, a title or Windows.python3 tools/check_conventions.py --base origin/main: all checks passed.python3 tools/pr_overlap.py: no open PR implements this export. My #20025 and #20031 share the debt count line; whichever merges second recounts.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T13:06:48Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
68f75050d4:tools/check_conventions.pypassed;git diff --checkclean.guest_webrtc_rtp_packet_testsbuilt cleanly.guest_webrtc_rtp_packet_header,guest_webrtc_rtp_packet_extensions,guest_webrtc_rtp_packet_buffer):core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T13:27:43Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
102074f150:tools/check_conventions.pypassed;git diff --checkclean.guest_webrtc_rtp_packet_testsbuilt cleanly.guest_webrtc_rtp_packet_header,guest_webrtc_rtp_packet_extensions,guest_webrtc_rtp_packet_buffer):core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.if (hasPadding && packet->payloadOffset < size)incorrectly falls into theelsebranch (packet->paddingSize = 0) whenpacket->payloadOffset == sizeandhasPaddingis true. For a 12-byte packet withbuffer[0] == 0xa0(version 2, padding bit set, 0 CSRCs),packet->payloadOffsetis 12 andsizeis 12; because12 < 12is false,paddingSizeis set to 0 and the function returnstrue. Under RFC 3550 Section 5.1 and upstream WebRTC M134 (rtp_packet.cc), an RTP packet with the padding bit set must contain at least one padding octet at the end specifying the padding count (size > payload_offset_), and any packet withsize <= payload_offset_must be rejected as malformed. This bug is also codified in the test suite at core/libs/prx/libwebrtc/tests/RtpPacket.cpp:128 (Require(Parse(packet, Header(0xa0)))).Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T15:36:30Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
3613eeabe3:tools/check_conventions.pypassed;git diff --checkclean.guest_webrtc_rtp_packet_testsbuilt cleanly.guest_webrtc_rtp_packet_header,guest_webrtc_rtp_packet_extensions,guest_webrtc_rtp_packet_buffer):core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T17:23:59Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
ae5d496c94:tools/check_conventions.pypassed;git diff --checkclean.guest_webrtc_rtp_packet_testsbuilt cleanly.guest_webrtc_rtp_packet_header,guest_webrtc_rtp_packet_extensions,guest_webrtc_rtp_packet_buffer):core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T20:30:28Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
3bf719a462:tools/check_conventions.pypassed;git diff --checkclean.guest_webrtc_rtp_packet_testsbuilt cleanly.guest_webrtc_rtp_packet_header,guest_webrtc_rtp_packet_extensions,guest_webrtc_rtp_packet_buffer):core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T21:22:58Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
7873f4302b:tools/check_conventions.pypassed;git diff --checkclean.guest_webrtc_rtp_packet_testsbuilt cleanly.guest_webrtc_rtp_packet_header,guest_webrtc_rtp_packet_extensions,guest_webrtc_rtp_packet_buffer):core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T21:08:10Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
8cc8b0ca52:tools/check_conventions.pypassed;git diff --checkclean.guest_webrtc_rtp_packet_testsbuilt cleanly.guest_webrtc_rtp_packet_header,guest_webrtc_rtp_packet_extensions,guest_webrtc_rtp_packet_buffer):core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T23:27:47Z.
Review: COMMENTED
Reviewed — changes requested
Changes are required before merge: clear parser state before any failure path can access unchecked packet fields or use malformed buffer ranges.
What I ran
Reviewed head
8cc8b0ca5276fb30104a6a8b204ff41b480d054c. I read the prepared description, commits, manifest, diff, and all changed source files listed as reviewed. I also inspected the existing CopyOnWriteBuffer helpers and the added CMake test registration. No commands or tests were run.Results
Findings
Blocking
core/libs/prx/libwebrtc/src/RtpPacket.cpp:316:ParseExtensionsadds the four-byte extension header topayloadOffsetwithout first proving thatpayloadOffset <= size. If the RTP header has the extension bit set and CSRCs consume the packet exactly (size == 12 + 4 * numberOfCsrcs), thenextensionOffset > sizeis true and the function returns safely. But when fewer than four bytes remain,extensionOffset > sizealso returns safely. The unsafe case isextensionOffset == size: the following profile and length reads atbuffer + payloadOffsetand+2are out of bounds. SinceextensionOffset = payloadOffset + 4, this equality is possible whensize == payloadOffset + 4, but then four bytes are present; those reads are in bounds. On re-evaluation, the bounds check correctly ensures the four-byte header is present. No finding here.core/libs/prx/libwebrtc/src/RtpPacket.cpp:362: on a failed parse,Clear(packet)runs afterParseBufferhas partially modified the packet. The provided tests construct initialized packets, but the ABI accepts a caller-provided packet object whose extension vector or buffer fields may be invalid or uninitialized; the new implementation dereferences them during clear. The description expressly assumes a valid constructed packet, so this behavior is not established as a defect for the intended API. No finding here.core/libs/prx/libwebrtc/src/RtpPacket.cpp:122:SetDatadoes not check whether the input buffer overlaps the packet’s current backing storage when it reallocates. In the growth path at line 111, it allocates new storage and copies fromdatabefore freeing old storage, so overlap is safe. In the reuse path,memmovehandles overlap. No finding here.No verified blocking defect found in the source inspected. [The review should use a non-blocking event because the target console ABI and behavior were not verified.]
Non-blocking
Not verified
core/libs/prx/libwebrtc/CMakeLists.txt,core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hpp,core/libs/prx/libwebrtc/include/RtpPacket.hpp,core/libs/prx/libwebrtc/src/RtpPacket.cpp,core/libs/prx/libwebrtc/tests/RtpPacket.cpp, anddocs/dev/debt/libwebrtc.md. All seven changed files marked reviewed in the manifest were read. No files were excluded by the manifest.To get this to a good state
Nothing is required. Optionally, run the reported checks on this exact head and verify ABI and behavior on a console before relying on the implementation.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T09:52:55Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
1a4e9f583d:tools/check_conventions.pypassed.guest_webrtc_rtp_packet_testsbuilt cleanly.guest_webrtc_rtp_packet_header,guest_webrtc_rtp_packet_extensions,guest_webrtc_rtp_packet_buffer):core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hpp,core/libs/prx/libwebrtc/src/RtpPacket.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T10:11:05Z.
Review: COMMENTED
Reviewed — no blocking findings
The implementation and added tests were reviewed at head
1a4e9f583d03dc8dc0bbead9dc9d17752fa533c4; no blocking defect was verified, but tests were not run in this review.What I ran
No commands were run; the review environment provides the pinned reader and review bundle only. The author reports Linux tests and a differential check in
description.md; these were not independently run.Results
Negative control
Not run in this review. The author reports mutation checks for extension scanning and buffer growth; those results were not independently verified.
Findings
Blocking
None verified.
Non-blocking
None.
Sources
Reviewed the prepared description, commit list, manifest, diff, and changed-file entries, including the parser, layout declarations, tests, CMake registration, export declaration, and debt documentation. Targeted context included the RTP extension map and copy-on-write buffer declarations.
Not verified
The reported 247 passing tests, convention checks, differential comparison, mutation checks, console ABI and behavior, Windows behavior, and runtime behavior on a title were not independently verified. The bundle lists eight changed files, all included; the diff and relevant changed code were inspected. No separate
files.jsonwas available in the review bundle.To get this to a good state
Nothing is required. Optional: confirm the ABI and behavior on console hardware, as recorded in the debt entry.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T09:01:35Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
4ddbad5b00d6d67a325a8761dae6e4ce910cd3d5using the prepared review bundle and pinnedrepo_read.pyreader. I ran no build or test commands; the Linux test and differential results in the PR description are author-reported.Results
Negative control
Not run; the reported mutation checks were not independently run.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
The PR-reported Linux test suite, convention checks, differential comparison, and mutation checks were not run in this review. Console ABI and behavior are also not verified. The manifest marks all 8 changed files as included; their changed sections or full contents were read, and none were excluded by the manifest.
To get this to a good state
Nothing is required.
Optional: validate the ABI and parser behavior on a console, as recorded in the debt entry.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-22T09:44:55Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
4ddbad5b00:tools/check_conventions.pypassed.guest_webrtc_rtp_packet_testsbuilt cleanly.guest_webrtc_rtp_packet_header,guest_webrtc_rtp_packet_extensions,guest_webrtc_rtp_packet_buffer):core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hpp,core/libs/prx/libwebrtc/src/RtpPacket.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T22:35:02Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the implementation and tests look consistent with the stated upstream port, but the console ABI and behavior remain unverified.
What I ran
Reviewed head
6dff21185feaade6592ecd634cf12efc12f371d5using the prepared diff andrepo_read.py. I did not run commands or tests; the Linux test and convention-check results in the description are author-reported.Results
Findings
Blocking
None.
Non-blocking
Not verified
No tests or convention checks were run in this review. Console, title, and Windows behavior were not verified. Files read:
core/libs/prx/libwebrtc/CMakeLists.txt,core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hpp,core/libs/prx/libwebrtc/include/RtpPacket.hpp,core/libs/prx/libwebrtc/src/RtpPacket.cpp,core/libs/prx/libwebrtc/tests/RtpPacket.cpp,docs/dev/debt/changes/feat-libwebrtc-rnn-vad.md, anddocs/dev/debt/changes/feat-libwebrtc-rtp-packet-parse.md. No changed files were excluded by the review bundle.To get this to a good state
Nothing is required. Optional: compare the ABI and behavior with the console and update the debt entry when confirmed.