From b826a7d733364f3aad5a8aeba12763e787dca7eb Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sun, 16 Jul 2023 08:36:04 +0200 Subject: [PATCH] asf: fix GUID reading on big endian platforms Setting the initial parts (data1_, data2_, data3_) from the bytes directly using memcpy() means that they will be interpreted depending on the platform endianness. For example, the initial 4 bytes of the ASF header are 0x30, 0x26, 0xB2, 0x75, which will be read as 0x3026B275 on big endian platforms, never matching the actual GUID (0x75B22630), which is always specified in little endian format. Hence, when reading a GUID from data, make sure to turn the GUID parts to little endian. This fixes the reading of ASF files on big endian platforms. Fixes commit bed8d3d93cc99cc294bdd895d797e8cd296da130 --- src/asfvideo.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/asfvideo.cpp b/src/asfvideo.cpp index aedd95f493..a3075b86a0 100644 --- a/src/asfvideo.cpp +++ b/src/asfvideo.cpp @@ -55,6 +55,11 @@ AsfVideo::GUIDTag::GUIDTag(const uint8_t* bytes) { std::copy_n(bytes + DWORD, WORD, reinterpret_cast(&data2_)); std::copy_n(bytes + DWORD + WORD, WORD, reinterpret_cast(&data3_)); std::copy(bytes + QWORD, bytes + 2 * QWORD, data4_.begin()); + if (isBigEndianPlatform()) { + data1_ = byteSwap(data1_, true); + data2_ = byteSwap(data2_, true); + data3_ = byteSwap(data3_, true); + } } std::string AsfVideo::GUIDTag::to_string() {