mirror of
https://github.com/taglib/taglib.git
synced 2026-11-15 19:08:48 -05:00
Fix ByteVector bounds checks (#1493)
ByteVector::endsWith underflows when the pattern is longer than the receiver. containsAt then uses an addition that can wrap, allowing an out-of-bounds memcmp and a process crash. Reject invalid pattern offsets before subtraction and compare against the remaining receiver length without overflowing.
This commit is contained in:
@@ -441,8 +441,11 @@ bool ByteVector::containsAt(const ByteVector &pattern, unsigned int offset, unsi
|
||||
patternLength = pattern.size();
|
||||
|
||||
// do some sanity checking -- all of these things are needed for the search to be valid
|
||||
if(patternLength == 0 || patternOffset >= patternLength || offset > size())
|
||||
return false;
|
||||
|
||||
const unsigned int compareLength = patternLength - patternOffset;
|
||||
if(offset + compareLength > size() || patternOffset >= pattern.size() || patternLength == 0)
|
||||
if(compareLength > size() - offset)
|
||||
return false;
|
||||
|
||||
return ::memcmp(data() + offset, pattern.data() + patternOffset, compareLength) == 0;
|
||||
@@ -455,7 +458,8 @@ bool ByteVector::startsWith(const ByteVector &pattern) const
|
||||
|
||||
bool ByteVector::endsWith(const ByteVector &pattern) const
|
||||
{
|
||||
return containsAt(pattern, size() - pattern.size());
|
||||
return pattern.size() <= size() &&
|
||||
containsAt(pattern, size() - pattern.size());
|
||||
}
|
||||
|
||||
ByteVector &ByteVector::replace(char oldByte, char newByte)
|
||||
|
||||
Reference in New Issue
Block a user