CVE-2026-58968 AI-generated analysis
platform/external/libopenapv, APV decoder metadata (src/oapv_vlc.c, src/oapv_metadata.c, src/oapv_bs.c)
Reworks metadata PBU payload parsing in libopenapv (oapvd_vlc_metadata, oapvm_set, meta_verify_mdp_data, oapv_bsr_sink). Filler payloads are now sunk and skipped like other payloads, and their 0xFF content is checked in meta_verify_mdp_data. Zero-size payloads are handled explicitly. The bitstream sink bound check is changed. The trailing filler size can no longer underflow. A follow-up commit moves the payload_data declaration into the loop.
Root cause
In oapvd_vlc_metadata (src/oapv_vlc.c), metadata payloads went through three different paths. (1) Filler payloads (OAPV_METADATA_FILLER) were consumed byte by byte with oapv_bsr_read after oapv_bsr_sink. oapv_bsr_read refills via fn_flush(bs, 4), so bs->cur can move ahead of the logical payload end. (2) Non-filler payloads were skipped with BSR_MOVE_BYTE_ALIGN. (3) Zero-size payloads set payload_data = NULL and then called oapvm_set, which rejected (NULL, 0) with OAPV_ERR_INVALID_ARGUMENT. After the loop, the trailing filler size was computed as target_read_size - (bs->cur - bs_start_pos) without checking that bs->cur - bs_start_pos <= target_read_size. A bs->cur that had moved too far therefore produced an unsigned underflow that was passed to oapvd_vlc_filler. Separately, oapv_bsr_sink (src/oapv_bs.c) checked bs->cur + BSW_GET_SINK_BYTE(bs) < bs->end, while the function itself rewinds bs->cur. Before the follow-up commit, payload_data was declared outside the while loop.
How the fix works
- Commit 198b9c404af1, src/oapv_vlc.c:oapvd_vlc_metadata: the payload_size > 0 / FILLER / else branches are collapsed into one path. It asserts BSR_GET_LEFT_BYTE(bs) >= payload_size, calls oapv_bsr_sink to get payload_data, sets payload_data = NULL when payload_size == 0, then always advances with BSR_MOVE_BYTE_ALIGN(bs, payload_size) before calling oapvm_set. Filler bytes are no longer read through oapv_bsr_read. The ENC_DEC_DUMP loop now reads bs->cur[i] directly.
- Commit 198b9c404af1, src/oapv_vlc.c:oapvd_vlc_metadata: a new oapv_assert_gv(target_read_size >= (bs->cur - bs_start_pos), ...) returns OAPV_ERR_MALFORMED_BITSTREAM before oapvd_vlc_filler is called, so the filler size argument cannot underflow.
- Commit 198b9c404af1, src/oapv_metadata.c:meta_verify_mdp_data: a new OAPV_METADATA_FILLER branch checks that each of the size bytes of the data passed to oapvm_set is 0xFF. Any other byte returns OAPV_ERR_MALFORMED_BITSTREAM.
- Commit 198b9c404af1, src/oapv_metadata.c:oapvm_set: the argument assertion now accepts (data == NULL && size == 0) as well as (data != NULL && size > 0).
- Commit 198b9c404af1, src/oapv_bs.c:oapv_bsr_sink: the bound assertion changes from bs->cur + BSW_GET_SINK_BYTE(bs) < bs->end to bs->cur - BSW_GET_SINK_BYTE(bs) < bs->end. The function then rewinds bs->cur by (bs->leftbits >> 3).
- Commit 976a4961360a, src/oapv_vlc.c:oapvd_vlc_metadata: the u8 *payload_data = NULL declaration moves from before the while loop to inside it, so each iteration starts with NULL. The commit message describes this as making the heap double-free fix robust.
Completeness
- All metadata payload types in oapvd_vlc_metadata now share one sink/skip path. Per-type validation (T35, MDCV, CLL, USER_DEFINED, FILLER) happens in meta_verify_mdp_data.
- The underflow guard covers only the trailing filler computation in oapvd_vlc_metadata. oapvd_vlc_filler itself and any other callers of it are not shown and are not changed.
- oapvm_set now accepts (NULL, 0). What oapvm_set does with a zero-size payload (allocation, replacement or freeing of an existing mdp) is not in the material, so the diff alone does not show whether the double-free named in commit 976a4961360a is fully closed.
- The ENC_DEC_DUMP-only loop reads bs->cur[i] for i < payload_size. That read is bounded by the preceding BSR_GET_LEFT_BYTE check, and it is a debug build path.
Behavior changes
- Metadata PBUs where the parsed position goes past pbu_size - 8 now fail with OAPV_ERR_MALFORMED_BITSTREAM instead of reaching oapvd_vlc_filler with a wrapped size.
- Zero-size metadata payloads are now passed to oapvm_set(..., NULL, 0) instead of being rejected with OAPV_ERR_INVALID_ARGUMENT.
- Any oapvm_set caller passing OAPV_METADATA_FILLER now gets OAPV_ERR_MALFORMED_BITSTREAM if any byte is not 0xFF. The decoder reports the same error code as before for bad filler content, but only after the stream position has been advanced.
- The bound check in oapv_bsr_sink uses bs->cur - BSW_GET_SINK_BYTE(bs) instead of bs->cur + BSW_GET_SINK_BYTE(bs), so it is less strict near bs->end.
Per major
- Android 14: Not affected per the bulletin. platform/external/libopenapv is not present in android-security-14.0.0_r31.
- Android 15: Not affected per the bulletin. platform/external/libopenapv is not present in android-security-15.0.0_r19.
- Android 16: Same fix: Google cherry-picked 198b9c404af1 (upstream PR #132) and the follow-up 976a4961360a into android-security-16.0.0_r10. 7/8 patched-region lines are present.
- Android 17: Adapted fix: resolved by upgrading libopenapv to upstream v0.2.1.3 (commit 7e65ec061875 in android-security-17.0.0_r3, METADATA version 390b5605c55e). 6/8 patched-region lines are present, so the code differs slightly from the Android 16 cherry-pick.
Unknowns
- The material does not include the body of oapvm_set or the metadata allocation and free logic, so the double-free sequence referenced in commit 976a4961360a cannot be reconstructed.
- The body of oapvd_vlc_filler and the definitions of BSW_GET_SINK_BYTE and BSR_MOVE_BYTE_ALIGN are not shown.
- The Android 17 upgrade diff shown contains only workflow and METADATA changes. The source changes in v0.2.1.3, and whether it includes upstream PR #132, are not visible.
- The material does not show which Android media component invokes the APV decoder on untrusted input.