diff --git a/Audio/WaveBankReader.cpp b/Audio/WaveBankReader.cpp index 34b04cb4..5135c99a 100644 --- a/Audio/WaveBankReader.cpp +++ b/Audio/WaveBankReader.cpp @@ -604,7 +604,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false) if (m_data.dwFlags & BANKDATA::TYPE_STREAMING) { - if (m_data.dwAlignment < ALIGNMENT_DVD) + if ((m_data.dwAlignment < ALIGNMENT_DVD) || (m_data.dwAlignment > ALIGNMENT_MAX)) return E_FAIL; if (m_data.dwAlignment % DVD_SECTOR_SIZE) return E_FAIL; @@ -655,7 +655,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false) expectedSize = uint64_t(m_data.dwEntryCount) * m_data.dwEntryNameElementSize; if (expectedSize > UINT32_MAX) { - return E_FAIL; + return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); } if (namesBytes >= static_cast(expectedSize)) @@ -1185,7 +1185,9 @@ HRESULT WaveBankReader::Impl::GetMetadata(uint32_t index, Metadata& metadata) co { const uint64_t offset = uint64_t(metadata.offsetBytes) + uint64_t(m_header.Segments[HEADER::SEGIDX_ENTRYWAVEDATA].dwOffset); if (offset > UINT32_MAX) + { return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); + } metadata.offsetBytes = static_cast(offset); } diff --git a/Src/BinaryReader.h b/Src/BinaryReader.h index 0f708edc..d95146ee 100644 --- a/Src/BinaryReader.h +++ b/Src/BinaryReader.h @@ -10,6 +10,7 @@ #pragma once +#include #include #include #include @@ -45,7 +46,7 @@ namespace DirectX { static_assert(std::is_standard_layout::value, "Can only read plain-old-data types"); - uint64_t byteCount = uint64_t(sizeof(T)) * uint64_t(elementCount); + const uint64_t byteCount = uint64_t(sizeof(T)) * uint64_t(elementCount); if (byteCount > UINT32_MAX) throw std::overflow_error("ReadArray");