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<int>(static_cast<double>(duration) / 10000.0
                     - static_cast<double>(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)
This commit is contained in:
manuaudio
2026-08-15 17:52:56 +02:00
committed by Urs Fleisch
parent c275891a77
commit 9e3285c988
+10 -2
View File
@@ -25,6 +25,8 @@
#include "asffile.h"
#include <limits>
#include <utility>
#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<int>(static_cast<double>(duration) / 10000.0 - static_cast<double>(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<double>(duration) / 10000.0 - static_cast<double>(preroll) + 0.5;
if(milliseconds > static_cast<double>(std::numeric_limits<int>::min()) &&
milliseconds < static_cast<double>(std::numeric_limits<int>::max()))
file->d->properties->setLengthInMilliseconds(static_cast<int>(milliseconds));
}
ByteVector ASF::File::FilePrivate::StreamPropertiesObject::guid() const