From 3672fa6dd2750d7d51b2e9a406773addfe6ec819 Mon Sep 17 00:00:00 2001 From: Urs Fleisch Date: Thu, 27 Aug 2026 17:35:54 +0200 Subject: [PATCH] ASF: Skip attributes with invalid data type (#1429) --- taglib/asf/asfattribute.cpp | 18 +++++++++++++----- taglib/asf/asffile.cpp | 15 +++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/taglib/asf/asfattribute.cpp b/taglib/asf/asfattribute.cpp index 955724df..81060003 100644 --- a/taglib/asf/asfattribute.cpp +++ b/taglib/asf/asfattribute.cpp @@ -26,6 +26,7 @@ #include "asfattribute.h" #include "tdebug.h" +#include "tutils.h" #include "asffile.h" #include "asfutils.h" @@ -171,26 +172,27 @@ ASF::Attribute ASF::Attribute::fromGuid(const ByteVector& guid) String ASF::Attribute::parse(ASF::File &file, int kind) { - unsigned int size, nameLength; + unsigned int size; + unsigned short nameLength, dataType; String name; d->pictureValue = Picture::fromInvalid(); // extended content descriptor if(kind == 0) { nameLength = readWORD(&file); name = readString(&file, nameLength); - d->type = static_cast(readWORD(&file)); + dataType = readWORD(&file); size = readWORD(&file); } // metadata & metadata library else { - int temp = readWORD(&file); + const unsigned short temp = readWORD(&file); // metadata library if(kind == 2) { d->language = temp; } d->stream = readWORD(&file); nameLength = readWORD(&file); - d->type = static_cast(readWORD(&file)); + dataType = readWORD(&file); size = readDWORD(&file); name = readString(&file, nameLength); } @@ -199,7 +201,7 @@ String ASF::Attribute::parse(ASF::File &file, int kind) debug("ASF::Attribute::parse() -- Value larger than 64kB"); } - switch(d->type) { + switch(dataType) { case WordType: d->numericValue = readWORD(&file); break; @@ -229,7 +231,13 @@ String ASF::Attribute::parse(ASF::File &file, int kind) case GuidType: d->byteVectorValue = file.readBlock(size); break; + + default: + debug(Utils::formatString( + "ASF::Attribute::parse() -- Unknown data type 0x%hx", dataType)); + return {}; } + d->type = static_cast(dataType); if(d->type == BytesType && name == "WM/Picture") { d->pictureValue.parse(d->byteVectorValue); diff --git a/taglib/asf/asffile.cpp b/taglib/asf/asffile.cpp index 33a11d8b..440744c8 100644 --- a/taglib/asf/asffile.cpp +++ b/taglib/asf/asffile.cpp @@ -330,8 +330,9 @@ void ASF::File::FilePrivate::ExtendedContentDescriptionObject::parse(ASF::File * } ASF::Attribute attribute; - String name = attribute.parse(*file); - file->d->tag->addAttribute(name, attribute); + if(String name = attribute.parse(*file); !name.isEmpty()) { + file->d->tag->addAttribute(name, attribute); + } if(file->tell() > end) { file->setValid(false); @@ -369,8 +370,9 @@ void ASF::File::FilePrivate::MetadataObject::parse(ASF::File *file, long long si } ASF::Attribute attribute; - String name = attribute.parse(*file, 1); - file->d->tag->addAttribute(name, attribute); + if(String name = attribute.parse(*file, 1); !name.isEmpty()) { + file->d->tag->addAttribute(name, attribute); + } if(file->tell() > end) { file->setValid(false); @@ -408,8 +410,9 @@ void ASF::File::FilePrivate::MetadataLibraryObject::parse(ASF::File *file, long } ASF::Attribute attribute; - String name = attribute.parse(*file, 2); - file->d->tag->addAttribute(name, attribute); + if(String name = attribute.parse(*file, 2); !name.isEmpty()) { + file->d->tag->addAttribute(name, attribute); + } if(file->tell() > end) { file->setValid(false);