CVE-2026-58953 AI-generated analysis
platform/external/libopenapv, APV decoder (src/oapv.c, src/oapv_vlc.c, src/oapv_bs.c)
Adds bounds validation of the APV tile header (tile_header_size, and each component's tile_data_size checked against the enclosing tile_size), tightens the check that a tile ends inside the input bitstream, and caps the Exp-Golomb prefix length in the VLC readers so that a malformed tile is rejected.
Root cause
In src/oapv_vlc.c:oapvd_vlc_tile_header, the per-component th->tile_data_size[c] values read from the bitstream were only checked to be > 0 and never compared with the tile's byte size. th->tile_header_size was not validated at all. In src/oapv.c:dec_thread_tile, the tile bound check used (data_size - 1) in unsigned arithmetic, which wraps when data_size is 0. dec_tile then parsed the tile header without passing any tile size bound. In addition, dec_vlc_read_kparam0 and dec_vlc_read put no limit on the number of leading zero bits (k), and oapvd_vlc_ac_coef did not reject negative run values. The bulletin classes this as type ID, severity High.
How the fix works
- src/oapv_vlc.c:oapvd_vlc_tile_header: the signature changes to (bs, num_comp, th, tile_size). It now requires th->tile_header_size == 5 + num_comp*5 and otherwise returns OAPV_ERR_MALFORMED_BITSTREAM. It tracks a cumulative read_size and, for each component, asserts (tile_size - read_size) >= th->tile_data_size[c] before adding that size to read_size. The old tile_data_size[c] > 0 check is removed. src/oapv_vlc.h is updated to match.
- src/oapv.c:dec_thread_tile: the tile field data_size is renamed to tile_size (src/oapv_def.h). The bound check becomes bs_beg + tile_size + OAPV_TILE_SIZE_LEN <= ctx->bs.end, using oapv_assert_gv with OAPV_ERR_MALFORMED_BITSTREAM. This removes the (data_size - 1) arithmetic.
- src/oapv.c:dec_tile: initializes the tile bitstream with tile->tile_size and calls oapvd_vlc_tile_header(&bs, ctx->num_comp, &tile->th, tile->tile_size).
- src/oapv_vlc.c:dec_vlc_read_kparam0 and dec_vlc_read: add oapv_assert_rv(k < 32, -1) after the leading-zero loop. src/oapv_vlc.c:oapvd_vlc_ac_coef: asserts run >= 0 and otherwise returns OAPV_ERR_MALFORMED_BITSTREAM.
- src/oapv_bs.c:oapv_bsr_init: zeroes the oapv_bs_t before setting its fields. dec_frm_finish no longer zeroes ctx->bs and now returns void.
- src/oapv_bs.c / src/oapv_bs.h: remove the unused oapv_bsr_clz_in_code, oapv_bsr_clz and oapv_bsr_peek functions and the tbl_zero_count4 table.
- src/oapv.c:oapvd_decode: zeroes stat at entry. When the tile threads fail, it clears the image hash (new oapv_imgb_clr_md5 in src/oapv_util.c) instead of computing it. It always calls dec_frm_finish, so the imgb is released even on error. Only after the success check does it fill frm_info, pbu_type and group_id and move bs to ctx->tile_end. stat->read is now accumulated once per PBU for every PBU type.
- app/oapv_app_enc.c: comment typo fix only.
Completeness
- Covers: an exact-length check on tile_header_size, a cumulative check of each component's tile_data_size against tile_size, a check of the tile end against the input buffer end, a k < 32 cap in both VLC readers, rejection of negative run values in oapvd_vlc_ac_coef, and no use of ctx->tile_end or frame info after a tile failure.
- The new check in oapvd_vlc_tile_header computes (tile_size - read_size) as u32. Nothing in the diff shows a lower bound requiring tile_size >= tile_header_size before the subtraction. The material does not show whether a smaller tile_size is rejected elsewhere, or whether the bitstream reader's own end pointer limits reads in that case.
- dec_vlc_read_1bit_read appears in the context but its k handling is not in the diff. The material does not show whether it has an equivalent cap.
- Only decoder paths are changed. Encoder-side oapve_vlc_* functions are untouched.
Behavior changes
- Tiles whose tile_header_size != 5 + 5*num_comp are now rejected with OAPV_ERR_MALFORMED_BITSTREAM.
- tile_header_size plus the per-component tile_data_size values must fit within tile_size. A tile_data_size[c] of 0 is no longer rejected, because the old > 0 check was removed.
- The tile end check is one byte stricter: the tile must end at or before ctx->bs.end.
- Exp-Golomb prefixes of 32 or more zero bits make dec_vlc_read and dec_vlc_read_kparam0 return -1. oapvd_vlc_ac_coef turns a negative run into OAPV_ERR_MALFORMED_BITSTREAM.
- oapvd_decode zeroes the caller's oapvd_stat_t on entry, accumulates stat->read for every PBU type, clears the imgb hash on failed frames, and no longer advances the bitstream to tile_end on failure.
- oapv_bsr_init now zero-fills the whole oapv_bs_t. oapv_bsr_peek, oapv_bsr_clz and oapv_bsr_clz_in_code are removed.
Per major
- Android 14: Not affected per the bulletin. The libopenapv project is not present in android-security-14.0.0_r31.
- Android 15: Not affected per the bulletin. The libopenapv project is not present in android-security-15.0.0_r19.
- Android 16: Fixed by backport commit 8a1be1e6c348 (Change-Id I474a00adb117cf9818eb0c6ca1f2a50181d8b968), which bundles upstream #190, #194, #196 and #197, in android-security-16.0.0_r10. The resolver reports 5/8 lines of the patched region present at that tag.
- Android 17: The resolver links commit 7e65ec061875, 'Upgrade libopenapv to v0.2.1.3', in android-security-17.0.0_r3 by change_id. The diff shown for it contains only METADATA and CI workflow changes, so the source form of the fix on 17 is not visible in the material. The resolver reports 6/8 lines of the patched region present.
Unknowns
- Which of the four bundled upstream commits corresponds to the specific CVE trigger. The bug_id links the whole bundle.
- The contents of oapvd_vlc_tile_size and dec_tile_comp, so the material does not show how the unchecked tile_data_size[c] was used before the fix.
- Whether the Android 17 v0.2.1.3 upgrade carries the same source changes. The diff shown for it contains only METADATA and CI files.
- Whether a tile_size smaller than tile_header_size is rejected elsewhere before the u32 subtraction in oapvd_vlc_tile_header.