Potential memory hazard due to AlignedBuffer& AlignedBuffer::operator=(&&)
The move assignment operator for AlignedBuffer does not check for self-move, so when an object is move-assigned to itself, its destructor is called and then a new object is constructed from the now-invalid original. This leaves the internal buffer pointer in an invalid state, which could later cause a double-free or use-after-free when the destructor runs.
Originally disclosed on Mozilla
- Fixed in 10 days
- Paid in 25 days
- Disclosed after 10 days
`AlignedBuffer& operator=(&&)` (`dom/media/MediaData.h`) creates an invalid member `UniquePtr<uint8_t[]> mBuffer` on self-move. The bug is that it doesn't check for self-move before calling `~AlignedBuffer()`, which invalidates the entire object. (Following code from `FIREFOX_122_0_RELEASE`):
'''
97: AlignedBuffer& operator=(AlignedBuffer&& aOther) noexcept {
98: this->~AlignedBuffer();
99: new (this) AlignedBuffer(std::move(aOther));
100: return *this;
101: }
'''
Line 99 then constructs a new object from the invalid object using the move constructor:
'''
87: AlignedBuffer(AlignedBuffer&& aOther) noexcept
88: : mData(aOther.mData),
89: mLength(aOther.mLength),
90: mBuffer(std::move(aOther.mBuffer)),
91: mCapacity(aOther.mCapacity) {
92: aOther.mData = nullptr;
93: aOther.mLength = 0;
94: aOther.mCapacity = 0;
95: }
'''
but the `mBuffer` member:
'''
246: UniquePtr<uint8_t[]> mBuffer;
'''
is never reinitialized, and thus retains the invalid value it received on line 98 (and which got moved to itself on line 90). That value eventually will get used by `~UniquePtr<uint8_t[]>()`, possibly releasing memory it doesn't own.
I don't know whether any code actually does a self-move.
https://bugzilla.mozilla.org/show_bug.cgi?id=1815108 might be related to this bug.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
If self-move occurs, the invalid buffer pointer could lead to releasing memory it doesn't own, potentially causing a crash or memory corruption; the reporter does not know whether any code actually performs a self-move.
What the attacker needed
Code performs self-move assignment
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A move assignment is a way to transfer ownership of resources from one object to another efficiently. If an object is assigned to itself, the code first destroys its own resources and then tries to move from the destroyed object, leaving a pointer that points to freed memory. Later, when the object is destroyed again, it may try to free the same memory twice, which can crash the program or be exploited.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.