Fix FragmentfailureRampdown thread safety and divide-by-zero#1371
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens ABR rampdown logic by fixing a thread-safety issue when copying the profile list during FragmentfailureRampdown, and by preventing a floating-point divide-by-zero when abrMaxBuffer is unset/zero. It also adds unit tests to validate the new guard behavior.
Changes:
- Add
abrMaxBuffer <= 0guard inFragmentfailureRampdownto avoid divide-by-zero (new and legacy ABR). - Make copying of
mProfilesthread-safe during rampdown (new ABR via lock; legacy ABR via new locked accessor). - Add L1 unit tests covering the
abrMaxBuffer == 0rampdown behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
abr/abr.cpp |
Adds abrMaxBuffer guard and locks mProfiles while copying in FragmentfailureRampdown. |
support/aampabr/HybridABRManager.cpp |
Adds abrMaxBuffer guard and uses a new locked profile-copy helper in rampdown. |
support/aampabr/ABRManager.h |
Adds getProfileInfoLocked() API for thread-safe access to the profile list. |
support/aampabr/ABRManager.cpp |
Implements getProfileInfoLocked() by copying mProfiles under mProfileLock. |
test/utests/tests/AampAbrTests/AbrTests.cpp |
Adds a unit test asserting rampdown returns 0 when abrMaxBuffer == 0 (new ABR). |
test/utests/tests/AampAbrTests/HybridAbrTests.cpp |
Adds a unit test asserting rampdown returns 0 when abrMaxBuffer == 0 (legacy ABR). |
Add mProfileLock guard when copying mProfiles in FragmentfailureRampdown. The vector was previously copied without holding the lock, which is undefined behavior if another thread calls clearProfiles()/addProfile() concurrently during a period transition. Add early return when abrMaxBuffer <= 0 to prevent floating-point divide-by-zero when computing buffer percentage. The AampAbrConfig constructor initializes abrMaxBuffer to 0, so if ReadPlayerConfig has not been called, the division produces Inf. For the legacy ABR, add a protected getProfileInfoLocked() helper to ABRManager so HybridABRManager can obtain a thread-safe copy of mProfiles without accessing private members directly. These races are extremely unlikely to manifest, but are addressed here for reasons of code correctness and future proofing. Applied to both new ABR (abr/abr.cpp) and legacy ABR (support/aampabr/HybridABRManager.cpp, ABRManager.h/cpp). L1 tests added for the abrMaxBuffer guard.
6ba62c2 to
d784a30
Compare
Abhi-jith-S
pushed a commit
that referenced
this pull request
May 12, 2026
…rofileLock and divide by zero (#1371) * Fix FragmentfailureRampdown thread safety and divide-by-zero Reason for Change: harden ABR rampdown logic by fixing a thread-safety issue when copying the profile list during FragmentfailureRampdown, and by preventing a floating-point divide-by-zero when abrMaxBuffer is unset/zero. It also adds unit tests to validate the new guard behavior. Add mProfileLock guard when copying mProfiles in FragmentfailureRampdown. The vector was previously copied without holding the lock, which is undefined behavior if another thread calls clearProfiles()/addProfile() concurrently during a period transition. Add early return when abrMaxBuffer <= 0 to prevent floating-point divide-by-zero when computing buffer percentage. The AampAbrConfig constructor initializes abrMaxBuffer to 0, so if ReadPlayerConfig has not been called, the division produces Inf. For the legacy ABR, add a protected getProfileInfoLocked() helper to ABRManager so HybridABRManager can obtain a thread-safe copy of mProfiles without accessing private members directly. These races are extremely unlikely to manifest, but are addressed here for reasons of code correctness and future proofing. Applied to both new ABR (abr/abr.cpp) and legacy ABR (support/aampabr/HybridABRManager.cpp, ABRManager.h/cpp). L1 tests added for the abrMaxBuffer guard. * Address PR review: remove unused getProfileInfo, fix duplicate log, update FragmentfailureRampdown doc Risk: Low Test Guidance: see ticket --------- Co-authored-by: Philip Stroffolino <philip_stroffolino@cable.comcast.com>
varshnie
pushed a commit
that referenced
this pull request
May 18, 2026
…rofileLock and divide by zero (#1371) * Fix FragmentfailureRampdown thread safety and divide-by-zero Reason for Change: harden ABR rampdown logic by fixing a thread-safety issue when copying the profile list during FragmentfailureRampdown, and by preventing a floating-point divide-by-zero when abrMaxBuffer is unset/zero. It also adds unit tests to validate the new guard behavior. Add mProfileLock guard when copying mProfiles in FragmentfailureRampdown. The vector was previously copied without holding the lock, which is undefined behavior if another thread calls clearProfiles()/addProfile() concurrently during a period transition. Add early return when abrMaxBuffer <= 0 to prevent floating-point divide-by-zero when computing buffer percentage. The AampAbrConfig constructor initializes abrMaxBuffer to 0, so if ReadPlayerConfig has not been called, the division produces Inf. For the legacy ABR, add a protected getProfileInfoLocked() helper to ABRManager so HybridABRManager can obtain a thread-safe copy of mProfiles without accessing private members directly. These races are extremely unlikely to manifest, but are addressed here for reasons of code correctness and future proofing. Applied to both new ABR (abr/abr.cpp) and legacy ABR (support/aampabr/HybridABRManager.cpp, ABRManager.h/cpp). L1 tests added for the abrMaxBuffer guard. * Address PR review: remove unused getProfileInfo, fix duplicate log, update FragmentfailureRampdown doc Risk: Low Test Guidance: see ticket --------- Co-authored-by: Philip Stroffolino <philip_stroffolino@cable.comcast.com>
varatharajan568
pushed a commit
that referenced
this pull request
May 20, 2026
…rofileLock and divide by zero (#1371) * Fix FragmentfailureRampdown thread safety and divide-by-zero Reason for Change: harden ABR rampdown logic by fixing a thread-safety issue when copying the profile list during FragmentfailureRampdown, and by preventing a floating-point divide-by-zero when abrMaxBuffer is unset/zero. It also adds unit tests to validate the new guard behavior. Add mProfileLock guard when copying mProfiles in FragmentfailureRampdown. The vector was previously copied without holding the lock, which is undefined behavior if another thread calls clearProfiles()/addProfile() concurrently during a period transition. Add early return when abrMaxBuffer <= 0 to prevent floating-point divide-by-zero when computing buffer percentage. The AampAbrConfig constructor initializes abrMaxBuffer to 0, so if ReadPlayerConfig has not been called, the division produces Inf. For the legacy ABR, add a protected getProfileInfoLocked() helper to ABRManager so HybridABRManager can obtain a thread-safe copy of mProfiles without accessing private members directly. These races are extremely unlikely to manifest, but are addressed here for reasons of code correctness and future proofing. Applied to both new ABR (abr/abr.cpp) and legacy ABR (support/aampabr/HybridABRManager.cpp, ABRManager.h/cpp). L1 tests added for the abrMaxBuffer guard. * Address PR review: remove unused getProfileInfo, fix duplicate log, update FragmentfailureRampdown doc Risk: Low Test Guidance: see ticket --------- Co-authored-by: Philip Stroffolino <philip_stroffolino@cable.comcast.com>
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.
Add mProfileLock guard when copying mProfiles in
FragmentfailureRampdown. The vector was previously copied without holding the lock, which is undefined behavior if another thread calls clearProfiles()/addProfile() concurrently during a period transition.
Add early return when abrMaxBuffer <= 0 to prevent floating-point divide-by-zero when computing buffer percentage. The AampAbrConfig constructor initializes abrMaxBuffer to 0, so if ReadPlayerConfig has not been called, the division produces Inf.
For the legacy ABR, add a protected getProfileInfoLocked() helper to ABRManager so HybridABRManager can obtain a thread-safe copy of mProfiles without accessing private members directly.
These races are extremely unlikely to manifest, but are addressed here for reasons of code correctness and future proofing.
Applied to both new ABR (abr/abr.cpp) and legacy ABR (support/aampabr/HybridABRManager.cpp, ABRManager.h/cpp). L1 tests added for the abrMaxBuffer guard.