Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 19 additions & 33 deletions fragmentcollector_hls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2204,7 +2204,7 @@ void TrackState::IndexPlaylist(bool IsRefresh, AampTime &culledSec)
aamp->SetIsLive(context->IsLive());
if(!IsLive())
{
aamp->getAampCacheHandler()->InsertToPlaylistCache(mPlaylistUrl, playlist.GetVector(), mEffectiveUrl,IsLive(),TrackTypeToMediaType(type));
aamp->getAampCacheHandler()->InsertToPlaylistCache(mPlaylistUrl, playlist, mEffectiveUrl,IsLive(),TrackTypeToMediaType(type));
}
if(eTRACK_VIDEO == type)
{
Expand Down Expand Up @@ -2333,9 +2333,7 @@ void TrackState::ProcessPlaylist(AampGrowableBuffer& newPlaylist, int http_error
}

AcquirePlaylistLock();
// Free previous playlist buffer and load with new one
playlist.Free();
playlist.Replace( &newPlaylist );
playlist = newPlaylist.ExtractVector();

AampTime culled{};
IndexPlaylist(true, culled);
Expand Down Expand Up @@ -2607,7 +2605,7 @@ std::string StreamAbstractionAAMP_HLS::GetPlaylistURI(TrackType trackType )
* @param playlist[in] playlist to scan to infer stream format
* @return StreamOutputFormat stream format
***************************************************************************/
StreamOutputFormat GetFormatFromFragmentExtension( const AampGrowableBuffer &playlist )
StreamOutputFormat GetFormatFromFragmentExtension( const std::vector<uint8_t> &playlist )
{
StreamOutputFormat format = FORMAT_INVALID;
lstring iter(reinterpret_cast<const char*>(playlist.data()),playlist.size());
Expand Down Expand Up @@ -3239,7 +3237,7 @@ AAMPStatusType StreamAbstractionAAMP_HLS::Init(TuneType tuneType)
aamp->SetCurlTimeout(aamp->mNetworkTimeoutMs, (AampCurlInstance)i);
}

if (aamp->getAampCacheHandler()->RetrieveFromPlaylistCache(aamp->GetManifestUrl(), mainManifest.GetVector(), aamp->GetManifestUrl(), eMEDIATYPE_MANIFEST))
if (aamp->getAampCacheHandler()->RetrieveFromPlaylistCache(aamp->GetManifestUrl(), mainManifest, aamp->GetManifestUrl(), eMEDIATYPE_MANIFEST))
{
AAMPLOG_WARN("StreamAbstractionAAMP_HLS: Main manifest retrieved from cache");
}
Expand All @@ -3254,7 +3252,7 @@ AAMPStatusType StreamAbstractionAAMP_HLS::Init(TuneType tuneType)
// take the original url before its gets changed in GetFile
std::string mainManifestOrigUrl = aamp->GetManifestUrl();
aamp->SetCurlTimeout(aamp->mManifestTimeoutMs, eCURLINSTANCE_MANIFEST_MAIN);
(void) aamp->GetFile(aamp->GetManifestUrl(), eMEDIATYPE_MANIFEST, this->mainManifest.GetVector(), aamp->GetManifestUrl(), http_error, &mainManifestdownloadTime, NULL, eCURLINSTANCE_MANIFEST_MAIN, true,NULL,NULL,0);//CID:82578 - checked return
(void) aamp->GetFile(aamp->GetManifestUrl(), eMEDIATYPE_MANIFEST, this->mainManifest, aamp->GetManifestUrl(), http_error, &mainManifestdownloadTime, NULL, eCURLINSTANCE_MANIFEST_MAIN, true,NULL,NULL,0);//CID:82578 - checked return
// Set playlist curl timeouts.
for (int i = eCURLINSTANCE_MANIFEST_PLAYLIST_VIDEO; i < (eCURLINSTANCE_MANIFEST_PLAYLIST_VIDEO + AAMP_TRACK_COUNT); i++)
{
Expand All @@ -3266,7 +3264,7 @@ AAMPStatusType StreamAbstractionAAMP_HLS::Init(TuneType tuneType)
{
aamp->profiler.ProfileEnd(PROFILE_BUCKET_MANIFEST);
AAMPLOG_TRACE("StreamAbstractionAAMP_HLS::downloaded manifest");
aamp->getAampCacheHandler()->InsertToPlaylistCache(mainManifestOrigUrl, mainManifest.GetVector(), aamp->GetManifestUrl(),false,eMEDIATYPE_MANIFEST);
aamp->getAampCacheHandler()->InsertToPlaylistCache(mainManifestOrigUrl, mainManifest, aamp->GetManifestUrl(),false,eMEDIATYPE_MANIFEST);
}
else
{
Expand Down Expand Up @@ -3475,7 +3473,7 @@ AAMPStatusType StreamAbstractionAAMP_HLS::Init(TuneType tuneType)
aamp->profiler.SetBandwidthBitsPerSecondAudio(audio->GetCurrentBandWidth());
if (audio->enabled)
{
if (aamp->getAampCacheHandler()->RetrieveFromPlaylistCache(audio->mPlaylistUrl, audio->playlist.GetVector(), audio->mEffectiveUrl, eMEDIATYPE_PLAYLIST_AUDIO))
if (aamp->getAampCacheHandler()->RetrieveFromPlaylistCache(audio->mPlaylistUrl, audio->playlist, audio->mEffectiveUrl, eMEDIATYPE_PLAYLIST_AUDIO))
{
AAMPLOG_INFO("StreamAbstractionAAMP_HLS::audio playlist retrieved from cache");
}
Expand All @@ -3486,7 +3484,7 @@ AAMPStatusType StreamAbstractionAAMP_HLS::Init(TuneType tuneType)
}
if (video && video->enabled)
{
if (aamp->getAampCacheHandler()->RetrieveFromPlaylistCache(video->mPlaylistUrl, video->playlist.GetVector(), video->mEffectiveUrl, eMEDIATYPE_PLAYLIST_VIDEO))
if (aamp->getAampCacheHandler()->RetrieveFromPlaylistCache(video->mPlaylistUrl, video->playlist, video->mEffectiveUrl, eMEDIATYPE_PLAYLIST_VIDEO))
{
AAMPLOG_INFO("StreamAbstractionAAMP_HLS::video playlist retrieved from cache");
}
Expand Down Expand Up @@ -3542,7 +3540,7 @@ AAMPStatusType StreamAbstractionAAMP_HLS::Init(TuneType tuneType)
}
if (subtitle->enabled)
{
if (aamp->getAampCacheHandler()->RetrieveFromPlaylistCache(subtitle->mPlaylistUrl, subtitle->playlist.GetVector(), subtitle->mEffectiveUrl, eMEDIATYPE_PLAYLIST_SUBTITLE))
if (aamp->getAampCacheHandler()->RetrieveFromPlaylistCache(subtitle->mPlaylistUrl, subtitle->playlist, subtitle->mEffectiveUrl, eMEDIATYPE_PLAYLIST_SUBTITLE))
{
AAMPLOG_INFO("StreamAbstractionAAMP_HLS::subtitle playlist retrieved from cache");
}
Expand Down Expand Up @@ -4761,10 +4759,10 @@ StreamAbstractionAAMP_HLS::StreamAbstractionAAMP_HLS(class PrivateInstanceAAMP *
id3_callback_t id3Handler,
ptsoffset_update_t ptsUpdate)
: StreamAbstractionAAMP(aamp, std::move(id3Handler)),
rate(rate), maxIntervalBtwPlaylistUpdateMs(DEFAULT_INTERVAL_BETWEEN_PLAYLIST_UPDATES_MS), mainManifest("mainManifest"), allowsCache(false), seekPosition(seekpos), mTrickPlayFPS(),
rate(rate), maxIntervalBtwPlaylistUpdateMs(DEFAULT_INTERVAL_BETWEEN_PLAYLIST_UPDATES_MS), allowsCache(false), seekPosition(seekpos), mTrickPlayFPS(),
enableThrottle(false), firstFragmentDecrypted(false), mStartTimestampZero(false), mNumberOfTracks(0), midSeekPtsOffset(0),
segDLFailCount(0), segDrmDecryptFailCount(0), mMediaCount(0),mProfileCount(0),
mLangList(),mIframeAvailable(false), thumbnailManifest("thumbnailManifest"), indexedTileInfo(),
mLangList(),mIframeAvailable(false), indexedTileInfo(),
mFirstPTS(0),mDiscoCheckMutex(),
mPtsOffsetUpdate{std::move(ptsUpdate)},
mDrmInterface(aamp),
Expand Down Expand Up @@ -4817,7 +4815,7 @@ TrackState::TrackState(TrackType type, StreamAbstractionAAMP_HLS* parent, Privat
mInjectInitFragment(false), mInitFragmentInfo(), mDrmKeyTagCount(0), mIndexingInProgress(false), mForceProcessDrmMetadata(false),
mDuration(0), mLastMatchedDiscontPosition(-1), mCulledSeconds(0),mCulledSecondsOld(0),
mEffectiveUrl(""), mPlaylistUrl(""), mFragmentURIFromIndex(),
mSyncAfterDiscontinuityInProgress(false), playlist("playlist"),
mSyncAfterDiscontinuityInProgress(false),
index(), targetDurationSeconds(1), mDeferredDrmKeyMaxTime(0), startTimeForPlaylistSync(0.0),
context(parent), fragmentEncrypted(false), mKeyTagChanged(false), mIVKeyChanged(false), mLastKeyTagIdx(0), mDrmInfo(),
mDrmMetaDataIndexPosition(0), mDrmMetaDataIndex(), mDiscontinuityIndex(), mKeyHashTable(), mPlaylistMutex(),
Expand All @@ -4831,7 +4829,6 @@ TrackState::TrackState(TrackType type, StreamAbstractionAAMP_HLS* parent, Privat
,fragmentEncChange(false)
,demuxOp(eStreamOp_NONE)
{
playlist.clear();
index.clear();
startTimeForPlaylistSync = 0.0;
mDrmMetaDataIndex.clear();
Expand All @@ -4849,15 +4846,6 @@ TrackState::TrackState(TrackType type, StreamAbstractionAAMP_HLS* parent, Privat
*/
TrackState::~TrackState()
{
playlist.Free();
// We could remove this. This is already done in MediaTrack destructor
int maxCachedFragmentsPerTrack = GETCONFIGVALUE(eAAMPConfig_MaxFragmentCached);
for (int j=0; j< maxCachedFragmentsPerTrack; j++)
{
aamp_utils::ClearAndRelease(mCachedFragment[j].fragment);
}
FlushIndex();
memset( mDrmInfo.iv, 0, sizeof(mDrmInfo.iv) );
}
Comment on lines 4845 to 4847
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

TrackState::~TrackState() became empty. Previously it explicitly zeroed mDrmInfo.iv; with the destructor now empty, the IV bytes can remain in freed memory until overwritten. Please restore secure clearing of sensitive DRM fields (e.g., explicitly zero mDrmInfo.iv, ideally using a clearing routine that won’t be optimized out).

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

@DomSyna DomSyna Mar 23, 2026

Choose a reason for hiding this comment

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

If a bad actor can access the released memory to read the transient init vector data they can also read the data structure, which will be much easier to find. For it to be properly secure it would have to live in the TEE.

The Init vector is often in the clear, so not really that secret.



Expand Down Expand Up @@ -4915,8 +4903,6 @@ StreamAbstractionAAMP_HLS::~StreamAbstractionAAMP_HLS()
}

aamp->SyncBegin();
this->thumbnailManifest.Free();
this->mainManifest.Free();
aamp->CurlTerm(eCURLINSTANCE_VIDEO, DEFAULT_CURL_INSTANCE_COUNT);
aamp->CurlTerm(eCURLINSTANCE_MANIFEST_PLAYLIST_VIDEO, AAMP_TRACK_COUNT);
aamp->SyncEnd();
Expand Down Expand Up @@ -5269,7 +5255,7 @@ bool StreamAbstractionAAMP_HLS::SetThumbnailTrack( int thumbIndex )
{
bool rc = false;
indexedTileInfo.clear();
thumbnailManifest.Free();
aamp_utils::ClearAndRelease(thumbnailManifest);
int iProfile{};

for (auto& streamInfo : streamInfoStore)
Expand All @@ -5290,7 +5276,7 @@ bool StreamAbstractionAAMP_HLS::SetThumbnailTrack( int thumbIndex )
AampTime downloadTime{};
std::string tempEffectiveUrl;
double tempDownloadTime;
if( aamp->GetFile(std::move(url), eMEDIATYPE_PLAYLIST_IFRAME, thumbnailManifest.GetVector(), tempEffectiveUrl, http_error, &tempDownloadTime, NULL, eCURLINSTANCE_MANIFEST_MAIN,true) )
if( aamp->GetFile(std::move(url), eMEDIATYPE_PLAYLIST_IFRAME, thumbnailManifest, tempEffectiveUrl, http_error, &tempDownloadTime, NULL, eCURLINSTANCE_MANIFEST_MAIN,true) )
{
downloadTime = tempDownloadTime;
AAMPLOG_WARN("In StreamAbstractionAAMP_HLS: Configured Thumbnail");
Expand All @@ -5303,7 +5289,7 @@ bool StreamAbstractionAAMP_HLS::SetThumbnailTrack( int thumbIndex )
}
rc=true;
}
aamp->getAampCacheHandler()->InsertToPlaylistCache(streamInfo.uri, thumbnailManifest.GetVector(), tempEffectiveUrl,false,eMEDIATYPE_PLAYLIST_IFRAME);
aamp->getAampCacheHandler()->InsertToPlaylistCache(streamInfo.uri, thumbnailManifest, tempEffectiveUrl,false,eMEDIATYPE_PLAYLIST_IFRAME);
if( ContentType_SLE != type && ContentType_LINEAR != type )
{
lstring iter = lstring(reinterpret_cast<const char*>(thumbnailManifest.data()), thumbnailManifest.size());
Expand Down Expand Up @@ -5399,11 +5385,11 @@ std::vector<ThumbnailData> StreamAbstractionAAMP_HLS::GetThumbnailRangeData(doub
std::vector<ThumbnailData> data{};
HlsStreamInfo &streamInfo = streamInfoStore[aamp->mthumbIndexValue];
ContentType type = aamp->GetContentType();
if(thumbnailManifest.capacity() == 0 || ( type == ContentType_SLE || type == ContentType_LINEAR ) )
if(thumbnailManifest.empty() || ( type == ContentType_SLE || type == ContentType_LINEAR ) )
{
thumbnailManifest.Free();
aamp_utils::ClearAndRelease(thumbnailManifest);
std::string tmpurl;
if(aamp->getAampCacheHandler()->RetrieveFromPlaylistCache(streamInfo.uri, thumbnailManifest.GetVector(), tmpurl,eMEDIATYPE_PLAYLIST_IFRAME))
if(aamp->getAampCacheHandler()->RetrieveFromPlaylistCache(streamInfo.uri, thumbnailManifest, tmpurl,eMEDIATYPE_PLAYLIST_IFRAME))
{
HandleSleThumbnailData( tStart, tEnd );
aamp->mLastSleThumbnailInfo.clear();
Expand Down Expand Up @@ -5754,7 +5740,7 @@ void TrackState::FetchPlaylist()
aamp->profiler.ProfileBegin(bucketId);

double tempDownloadTime{};
(void) aamp->GetFile(mPlaylistUrl, mType, playlist.GetVector(), mEffectiveUrl, http_error, &tempDownloadTime, NULL, (unsigned int)dnldCurlInstance, true );
(void) aamp->GetFile(mPlaylistUrl, mType, playlist, mEffectiveUrl, http_error, &tempDownloadTime, NULL, (unsigned int)dnldCurlInstance, true );
downloadTime = tempDownloadTime;
// update videoend info
main_error = context->getOriginalCurlError(http_error);
Expand Down
8 changes: 4 additions & 4 deletions fragmentcollector_hls.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ class TrackState : public MediaTrack
public:
std::string mEffectiveUrl; /**< uri associated with downloaded playlist (takes into account 302 redirect) */
std::string mPlaylistUrl; /**< uri associated with downloaded playlist */
AampGrowableBuffer playlist; /**< downloaded playlist contents */
std::vector<uint8_t> playlist{}; /**< downloaded playlist contents */

AampTime mProgramDateTime;
std::vector<IndexNode> index;
Expand Down Expand Up @@ -864,7 +864,7 @@ class StreamAbstractionAAMP_HLS : public StreamAbstractionAAMP
* @return void.
***************************************************************************/
void HandleSleThumbnailData(double tStart, double tEnd);
AampGrowableBuffer thumbnailManifest; /**< Thumbnail manifest buffer holder */
std::vector<uint8_t> thumbnailManifest{}; /**< Thumbnail manifest buffer holder */
std::vector<TileInfo> indexedTileInfo; /**< Indexed Thumbnail information */
double indexedTileEndTime; /**< endTime received from player applications */
/***************************************************************************
Expand Down Expand Up @@ -907,7 +907,7 @@ class StreamAbstractionAAMP_HLS : public StreamAbstractionAAMP
TrackState* trackState[AAMP_TRACK_COUNT]{}; /**< array to store all tracks of a stream */
float rate; /**< Rate of playback */
int maxIntervalBtwPlaylistUpdateMs; /**< Interval between playlist update */
AampGrowableBuffer mainManifest; /**< Main manifest buffer holder */
std::vector<uint8_t> mainManifest{}; /**< Main manifest buffer holder */
bool allowsCache; /**< Flag indicating if playlist needs to be cached or not */
std::vector<HlsStreamInfo> streamInfoStore{}; /**< Store of multiple stream information */
std::vector<MediaInfo> mediaInfoStore{}; /**< Store of multiple media within stream */
Expand Down Expand Up @@ -1132,6 +1132,6 @@ class StreamAbstractionAAMP_HLS : public StreamAbstractionAAMP
std::unique_ptr<aamp::MetadataProcessorIntf> mMetadataProcessor;
};

StreamOutputFormat GetFormatFromFragmentExtension( const AampGrowableBuffer &playlist );
StreamOutputFormat GetFormatFromFragmentExtension( const std::vector<uint8_t> &playlist );

#endif // FRAGMENTCOLLECTOR_HLS_H
2 changes: 1 addition & 1 deletion test/utests/fakes/FakeFragmentCollector_HLS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
StreamAbstractionAAMP_HLS::StreamAbstractionAAMP_HLS(class PrivateInstanceAAMP *aamp,double seekpos, float rate,
id3_callback_t id3Handler,
ptsoffset_update_t ptsOffsetUpdate)
: StreamAbstractionAAMP(aamp), mainManifest("mainManifest"), thumbnailManifest("thumbnailManifest"),mDrmInterface(aamp)
: StreamAbstractionAAMP(aamp), mDrmInterface(aamp)
{
}

Expand Down
Loading
Loading