Skip to content

RDKEMW-28267: Buffer bounds - ClearKey subsample validation, subtec map/memmove, cdmidecryptor unmap - #333

Open
jaihere4u wants to merge 1 commit into
developfrom
mpi-audit-buffer-bounds
Open

jaihere4u wants to merge 1 commit into
developfrom
mpi-audit-buffer-bounds

Conversation

@jaihere4u

@jaihere4u jaihere4u commented Nov 4, 2026 •

Copy link
Copy Markdown

Jira: RDKEMW-28267 - Middleware PI memory & reliability audit.

Findings covered: BUF-01/02/03 (see ticket + attached MPI_Memory_Audit.html for file:line evidence).

Static-analysis findings; no runtime metrics yet - unit tests + sanitizer runs required before merge.

ClearKeyDrmSession: bound-check each subsample's clear/encrypted ranges
against the mapped buffer size and the pbData scratch before every
memcpy — a corrupt subsample table could otherwise drive OOB reads of
the GstBuffer and OOB writes past the malloc'd scratch.

gstsubtecmp4transform: check gst_buffer_map result before using the
map (uninitialized GstMapInfo on failure), and use memmove for the
mdat-shift copy which overlaps within the same buffer.

gstcdmidecryptor: only gst_buffer_unmap the subsamples buffer when the
preceding gst_buffer_map succeeded — previously the free_resources path
unmapped a never-mapped buffer with an uninitialized GstMapInfo.
@jaihere4u
jaihere4u requested a review from a team as a code owner November 4, 2026 03:59
Copilot AI balanced review requested due to automatic review settings November 4, 2026 03:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical bounds errors permit an eight-byte overread during MP4 payload copying and an out-of-bounds DRM scratch-buffer write caused by 32-bit counter overflow.

2 open issues
What changed in this PR

This PR hardens buffer handling in the middleware player’s DRM and subtitle paths as part of the memory and reliability audit.

Changes:

  • Adds bounds checks when gathering and copying back ClearKey subsample data.
  • Checks subtitle buffer mapping and replaces an overlapping memcpy with memmove.
  • Tracks successful subsample mapping to guard decryptor cleanup.
File Description
gst-plugins/​gst_subtec/​gstsubtecmp4transform.cpp Handles mapping failure and uses overlap-safe copying.
gst-plugins/​drm/​gst/​gstcdmidecryptor.cpp Unmaps subsample data only after a successful map.
drm/​ClearKeyDrmSession.cpp Adds bounds validation around subsample copies.

Review effort: Balanced

Comment on lines 442 to +454
// Skip the clear byte range from source buffer.
iCurrSource += nBytesClear;

// Bounds-check the subsample ranges against the mapped buffer
// and the pbData scratch (sized to bufferMap.size). A corrupt
// subsample table must not read/write out of bounds.
if ((uint64_t)iCurrSource + nBytesEncrypted > bufferMap.size
|| (uint64_t)cbData + nBytesEncrypted > bufferMap.size)
{
MW_LOG_ERR("ClearKeySession: ERROR : subsample range exceeds buffer size %zu", bufferMap.size);
cbData = 0;
break;
}
{
GST_DEBUG_OBJECT (subtecmp4transform, "offset %zu length %zu", offset, length);
memcpy(map.data, map.data + offset, length);
memmove(map.data, map.data + offset, length);
@jaihere4u jaihere4u changed the title MPI audit: Buffer bounds: ClearKey subsample validation, subtec map/memmove, cdmidecryptor unmap RDKEMW-28267: Buffer bounds - ClearKey subsample validation, subtec map/memmove, cdmidecryptor unmap Nov 4, 2026
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