Repository navigation
RDKEMW-28267: Buffer bounds - ClearKey subsample validation, subtec map/memmove, cdmidecryptor unmap - #333
Open
jaihere4u wants to merge 1 commit into
Open
RDKEMW-28267: Buffer bounds - ClearKey subsample validation, subtec map/memmove, cdmidecryptor unmap#333jaihere4u wants to merge 1 commit into
jaihere4u wants to merge 1 commit into
Conversation
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.
Contributor
There was a problem hiding this comment.
🟡 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
memcpywithmemmove. - 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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.