From 9e3285c988bc2832ae7ded78332f306845d3254c Mon Sep 17 00:00:00 2001 From: manuaudio Date: Fri, 14 Aug 2026 23:58:49 -0700 Subject: [PATCH] ASF: do not convert an out of range length to int Third instance of the same shape as the DSF and DSDIFF changes: static_cast(static_cast(duration) / 10000.0 - static_cast(preroll) + 0.5) duration and preroll are both long long values read from the file properties object, so the result can land outside int, and converting a double the destination type cannot represent is undefined: taglib/asf/asffile.cpp:240:22: runtime error: -2.80375e+14 is outside the range of representable values of type 'int' Only skip the conversion when the value will not fit. Values that do fit, negative ones included, are set exactly as before, so the three .wma files in tests/data still report lengthMs 3549, 96502 and 3712. Found by the same fuzzing that turned up the DSF case. Assisted-By: Claude Code (Claude Opus 5) --- taglib/asf/asffile.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/taglib/asf/asffile.cpp b/taglib/asf/asffile.cpp index bba49663..9f40df31 100644 --- a/taglib/asf/asffile.cpp +++ b/taglib/asf/asffile.cpp @@ -25,6 +25,8 @@ #include "asffile.h" +#include + #include #include "tdebug.h" @@ -236,8 +238,14 @@ void ASF::File::FilePrivate::FilePropertiesObject::parse(ASF::File *file, long l const long long duration = data.toLongLong(40, false); const long long preroll = data.toLongLong(56, false); - file->d->properties->setLengthInMilliseconds( - static_cast(static_cast(duration) / 10000.0 - static_cast(preroll) + 0.5)); + // duration and preroll are both read from the file, so the result can land outside + // int, and converting a double the destination type cannot represent is undefined. + const double milliseconds = + static_cast(duration) / 10000.0 - static_cast(preroll) + 0.5; + + if(milliseconds > static_cast(std::numeric_limits::min()) && + milliseconds < static_cast(std::numeric_limits::max())) + file->d->properties->setLengthInMilliseconds(static_cast(milliseconds)); } ByteVector ASF::File::FilePrivate::StreamPropertiesObject::guid() const