summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--XMPFiles/source/FormatSupport/WAVE/WAVEBehavior.cpp7
-rw-r--r--XMPFiles/source/FormatSupport/WAVE/WAVEBehavior.h52
2 files changed, 57 insertions, 2 deletions
diff --git a/XMPFiles/source/FormatSupport/WAVE/WAVEBehavior.cpp b/XMPFiles/source/FormatSupport/WAVE/WAVEBehavior.cpp
index 0c39b8a..3c1fd77 100644
--- a/XMPFiles/source/FormatSupport/WAVE/WAVEBehavior.cpp
+++ b/XMPFiles/source/FormatSupport/WAVE/WAVEBehavior.cpp
@@ -599,13 +599,16 @@ bool WAVEBehavior::parseDS64Chunk( const Chunk& ds64Chunk, WAVEBehavior::DS64& d
const XMP_Uns8* data;
XMP_Uns64 size = ds64Chunk.getData(&data);
- memset( &ds64, 0, kMinimumDS64ChunkSize);
+ // (Exempi) Unsafe for memset
+ ds64 = WAVEBehavior::DS64();
+ // memset( &ds64, 0, kMinimumDS64ChunkSize);
//
// copy fix input data into RF64 block (except chunk size table)
// Safe as fixed size matches size of struct that is #pragma packed(1)
//
- memcpy( &ds64, data, kMinimumDS64ChunkSize );
+ ds64.From(data, kMinimumDS64ChunkSize);
+ // memcpy( &ds64, data, kMinimumDS64ChunkSize );
// If there is more data but the table length is <= 0 then this is not a valid ds64 chunk
if (size > kMinimumDS64ChunkSize && ds64.tableLength > 0 && ((size - kMinimumDS64ChunkSize) >= (ds64.tableLength * sizeof(ChunkSize64))))
diff --git a/XMPFiles/source/FormatSupport/WAVE/WAVEBehavior.h b/XMPFiles/source/FormatSupport/WAVE/WAVEBehavior.h
index 3e5b590..4b0da0d 100644
--- a/XMPFiles/source/FormatSupport/WAVE/WAVEBehavior.h
+++ b/XMPFiles/source/FormatSupport/WAVE/WAVEBehavior.h
@@ -44,6 +44,17 @@ public:
XMP_Uns32 id;
// Ctor
ChunkSize64(): size(0), id(0) {}
+ // (Exempi) we need a from buffer
+ constexpr static size_t dataSize() {
+ return sizeof(size) + sizeof(id);
+ }
+ // (Exempi) This code is not endian neutreal
+ size_t From(const XMP_Uns8* data) {
+ size = *(const XMP_Uns64*)data;
+ data += sizeof(size);
+ id = *(const XMP_Uns32*)data;
+ return dataSize();
+ }
};
struct DS64
@@ -58,6 +69,47 @@ public:
// ctor
DS64(): riffSize(0), dataSize(0), sampleCount(0), tableLength(0), trailingBytes(0) {}
+ // (Exempi) we need a from buffer
+ constexpr static size_t preludeSize() {
+ return sizeof(riffSize) + sizeof(dataSize) + sizeof(sampleCount)
+ + sizeof(tableLength);
+ }
+ // (Exempi) This code is not endian neutreal
+ size_t From(const XMP_Uns8* data, size_t s) {
+ size_t copied = 0;
+ if (s < preludeSize()) {
+ return copied;
+ }
+ riffSize = *(const XMP_Uns64*)data;
+ data += sizeof(riffSize);
+ dataSize = *(const XMP_Uns64*)data;
+ data += sizeof(dataSize);
+ sampleCount = *(const XMP_Uns64*)data;
+ data += sizeof(sampleCount);
+ tableLength = *(const XMP_Uns32*)data;
+ data += sizeof(tableLength);
+ copied += preludeSize();
+
+ if (s - copied >= sizeof(trailingBytes)) {
+ trailingBytes = *(const XMP_Uns32*)data;
+ data += sizeof(trailingBytes);
+ copied += sizeof(trailingBytes);
+
+ size_t idx = 0;
+ table.resize((s - copied) / ChunkSize64::dataSize());
+ while (s - copied) {
+ if (s - copied >= ChunkSize64::dataSize()) {
+ size_t b = table[idx].From(data);
+ data += b;
+ copied += b;
+ }
+ else {
+ break;
+ }
+ }
+ }
+ return copied;
+ }
};
#if SUNOS_SPARC || SUNOS_X86
#pragma pack ( )