Skip to content

decoder: Reject out of range u4_disp_buf_id in rel_display_frame - #164

Merged
harishdm merged 1 commit into
ittiam-systems:mainfrom
sage-mode-hunter:rel-display-buf-id-bounds
Nov 29, 2026
Merged

harishdm merged 1 commit into
ittiam-systems:mainfrom
sage-mode-hunter:rel-display-buf-id-bounds

Conversation

@sage-mode-hunter

@sage-mode-hunter sage-mode-hunter commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

u4_disp_buf_id arrives from the application in IVD_CMD_REL_DISPLAY_FRAME and reaches two fixed size arrays in the decoder context with no range check:

  • ih264d_rel_display_frame() and isvcd_rel_display_frame() index u4_disp_buf_mapping[] and u4_disp_buf_to_be_freed[], both MAX_DISP_BUFS_NEW (64) entries in dec_struct_t, with it directly
  • api_check_struct_sanity() validates only the ip/op struct sizes for this command, so nothing bounds the id on the way in
  • the sibling IVD_CMD_SET_DISPLAY_FRAME path already clamps num_disp_bufs to MAX_DISP_BUFS_NEW, which is what makes the asymmetry stand out

Repro on an unpatched build: create a decoder, then one IVD_CMD_REL_DISPLAY_FRAME with u4_disp_buf_id = 2048.

==33838==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62f00000def0
WRITE of size 4 at 0x62f00000def0 thread T0
    #0 ih264d_rel_display_frame ih264d_api.c:3896
    #1 ih264d_api_function ih264d_api.c:4695

0x62f00000def0 is located 4368 bytes after 51680-byte region [0x62f000000400,0x62f00000cde0)
allocated by thread T0 here:
    #2 ih264d_allocate_static_bufs ih264d_api.c:1557
    #3 ih264d_create ih264d_api.c:1882

Ids 0 to 63 behave as before; out of range ids now fail with IVD_UNSUPPORTEDPARAM instead of writing past the context. The MVC decoder has no IVD_CMD_REL_DISPLAY_FRAME handler, so there is nothing to change there.

ctest is green (16/16) and the default build is clean; decoder/svc/isvcd_api.c compiles clean with -DENABLE_SVC=ON.

Comment thread tests/decoder/DecHelper.cpp Resolved
u4_disp_buf_id arrives from the application in IVD_CMD_REL_DISPLAY_FRAME and
is used directly as an index into u4_disp_buf_mapping[] and
u4_disp_buf_to_be_freed[], both MAX_DISP_BUFS_NEW entry arrays in
dec_struct_t. api_check_struct_sanity() validates only the ip/op struct
sizes for this command, so an id outside that range writes past the
decoder context in ih264d_rel_display_frame() and
isvcd_rel_display_frame().

Reject ids outside the arrays in api_check_struct_sanity() in both
decoders, matching the clamp the IVD_CMD_SET_DISPLAY_FRAME path already
applies to num_disp_bufs. Ids within range are unaffected.
@sage-mode-hunter
sage-mode-hunter force-pushed the rel-display-buf-id-bounds branch from 0c11782 to 74763aa Compare November 29, 2026 10:26
@harishdm
harishdm merged commit 133b257 into ittiam-systems:main Nov 29, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants