mirror of
https://github.com/taglib/taglib.git
synced 2026-08-14 06:17:00 -04:00
APE: limit parsed tag item count (#1411)
An APEv2 footer controls the number of parsed items without a bound. A small crafted tag can therefore allocate a large item map and terminate a memory-constrained application. Stop parsing after 50,000 items. This matches existing parser count limits and preserves entries parsed before the limit.
This commit is contained in:
@@ -49,6 +49,7 @@ namespace
|
||||
{
|
||||
constexpr unsigned int MinKeyLength = 2;
|
||||
constexpr unsigned int MaxKeyLength = 255;
|
||||
constexpr unsigned int MAX_APE_ITEM_COUNT = 50000;
|
||||
|
||||
const String FRONT_COVER("COVER ART (FRONT)");
|
||||
const String BACK_COVER("COVER ART (BACK)");
|
||||
@@ -471,6 +472,11 @@ void APE::Tag::parse(const ByteVector &data)
|
||||
|
||||
for(unsigned int i = 0; i < d->footer.itemCount() && pos <= data.size() - 11; i++) {
|
||||
|
||||
if(i >= MAX_APE_ITEM_COUNT) {
|
||||
debug("APE::Tag::parse() - Maximum item count exceeded. Stopped parsing.");
|
||||
return;
|
||||
}
|
||||
|
||||
const int nullPos = data.find('\0', pos + 8);
|
||||
if(nullPos < 0) {
|
||||
debug("APE::Tag::parse() - Couldn't find a key/value separator. Stopped parsing.");
|
||||
|
||||
Reference in New Issue
Block a user