This commit is contained in:
Chuck Walbourn 2023-02-08 11:12:26 -08:00 коммит произвёл GitHub
Родитель 2b09bdad5f
Коммит 2fa8df3967
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 100 добавлений и 24 удалений

Просмотреть файл

@ -122,11 +122,15 @@ namespace
const RIFFChunk* FindChunk(
_In_reads_bytes_(sizeBytes) const uint8_t* data,
_In_ size_t sizeBytes,
_In_ const uint8_t* upperBound,
_In_ uint32_t tag) noexcept
{
if (!data)
return nullptr;
if (sizeBytes < sizeof(RIFFChunk))
return nullptr;
const uint8_t* ptr = data;
const uint8_t* end = data + sizeBytes;
@ -136,8 +140,14 @@ namespace
if (header->tag == tag)
return header;
auto const offset = header->size + sizeof(RIFFChunk);
ptr += offset;
const uint64_t offset = static_cast<uint64_t>(header->size) + sizeof(RIFFChunk);
if (offset >= UINT32_MAX)
return nullptr;
ptr += static_cast<size_t>(offset);
if (ptr > upperBound)
return nullptr;
}
return nullptr;
@ -167,7 +177,7 @@ namespace
const uint8_t* wavEnd = wavData + wavDataSize;
// Locate RIFF 'WAVE'
auto riffChunk = FindChunk(wavData, wavDataSize, FOURCC_RIFF_TAG);
auto riffChunk = FindChunk(wavData, wavDataSize, wavEnd, FOURCC_RIFF_TAG);
if (!riffChunk || riffChunk->size < 4)
{
return E_FAIL;
@ -186,7 +196,7 @@ namespace
return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF);
}
auto fmtChunk = FindChunk(ptr, riffHeader->size, FOURCC_FORMAT_TAG);
auto fmtChunk = FindChunk(ptr, riffHeader->size, wavEnd, FOURCC_FORMAT_TAG);
if (!fmtChunk || fmtChunk->size < sizeof(PCMWAVEFORMAT))
{
return E_FAIL;
@ -295,7 +305,7 @@ namespace
return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF);
}
auto dataChunk = FindChunk(ptr, riffChunk->size, FOURCC_DATA_TAG);
auto dataChunk = FindChunk(ptr, riffChunk->size, wavEnd, FOURCC_DATA_TAG);
if (!dataChunk || !dataChunk->size)
{
return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
@ -335,7 +345,7 @@ namespace
const uint8_t* wavEnd = wavData + wavDataSize;
// Locate RIFF 'WAVE'
auto riffChunk = FindChunk(wavData, wavDataSize, FOURCC_RIFF_TAG);
auto riffChunk = FindChunk(wavData, wavDataSize, wavEnd, FOURCC_RIFF_TAG);
if (!riffChunk || riffChunk->size < 4)
{
return E_FAIL;
@ -360,7 +370,7 @@ namespace
return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF);
}
auto dlsChunk = FindChunk(ptr, riffChunk->size, FOURCC_DLS_SAMPLE);
auto dlsChunk = FindChunk(ptr, riffChunk->size, wavEnd, FOURCC_DLS_SAMPLE);
if (dlsChunk)
{
ptr = reinterpret_cast<const uint8_t*>(dlsChunk) + sizeof(RIFFChunk);
@ -391,7 +401,7 @@ namespace
}
// Locate 'smpl' (Sample Chunk)
auto midiChunk = FindChunk(ptr, riffChunk->size, FOURCC_MIDI_SAMPLE);
auto midiChunk = FindChunk(ptr, riffChunk->size, wavEnd, FOURCC_MIDI_SAMPLE);
if (midiChunk)
{
ptr = reinterpret_cast<const uint8_t*>(midiChunk) + sizeof(RIFFChunk);
@ -447,7 +457,7 @@ namespace
const uint8_t* wavEnd = wavData + wavDataSize;
// Locate RIFF 'WAVE'
auto riffChunk = FindChunk(wavData, wavDataSize, FOURCC_RIFF_TAG);
auto riffChunk = FindChunk(wavData, wavDataSize, wavEnd, FOURCC_RIFF_TAG);
if (!riffChunk || riffChunk->size < 4)
{
return E_FAIL;
@ -466,7 +476,7 @@ namespace
return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF);
}
auto tableChunk = FindChunk(ptr, riffChunk->size, tag);
auto tableChunk = FindChunk(ptr, riffChunk->size, wavEnd, tag);
if (tableChunk)
{
ptr = reinterpret_cast<const uint8_t*>(tableChunk) + sizeof(RIFFChunk);

Просмотреть файл

@ -109,11 +109,15 @@ namespace
const RIFFChunk* FindChunk(
_In_reads_bytes_(sizeBytes) const uint8_t* data,
_In_ size_t sizeBytes,
_In_ const uint8_t* upperBound,
_In_ uint32_t tag) noexcept
{
if (!data)
return nullptr;
if (sizeBytes < sizeof(RIFFChunk))
return nullptr;
const uint8_t* ptr = data;
const uint8_t* end = data + sizeBytes;
@ -123,8 +127,14 @@ namespace
if (header->tag == tag)
return header;
auto const offset = header->size + sizeof(RIFFChunk);
ptr += offset;
const uint64_t offset = static_cast<uint64_t>(header->size) + sizeof(RIFFChunk);
if (offset >= UINT32_MAX)
return nullptr;
ptr += static_cast<size_t>(offset);
if (ptr > upperBound)
return nullptr;
}
return nullptr;
@ -154,7 +164,7 @@ namespace
const uint8_t* wavEnd = wavData + wavDataSize;
// Locate RIFF 'WAVE'
auto riffChunk = FindChunk(wavData, wavDataSize, FOURCC_RIFF_TAG);
auto riffChunk = FindChunk(wavData, wavDataSize, wavEnd, FOURCC_RIFF_TAG);
if (!riffChunk || riffChunk->size < 4)
{
return E_FAIL;
@ -173,7 +183,7 @@ namespace
return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF);
}
auto fmtChunk = FindChunk(ptr, riffHeader->size, FOURCC_FORMAT_TAG);
auto fmtChunk = FindChunk(ptr, riffHeader->size, wavEnd, FOURCC_FORMAT_TAG);
if (!fmtChunk || fmtChunk->size < sizeof(PCMWAVEFORMAT))
{
return E_FAIL;
@ -282,7 +292,7 @@ namespace
return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF);
}
auto dataChunk = FindChunk(ptr, riffChunk->size, FOURCC_DATA_TAG);
auto dataChunk = FindChunk(ptr, riffChunk->size, wavEnd, FOURCC_DATA_TAG);
if (!dataChunk || !dataChunk->size)
{
return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
@ -322,7 +332,7 @@ namespace
const uint8_t* wavEnd = wavData + wavDataSize;
// Locate RIFF 'WAVE'
auto riffChunk = FindChunk(wavData, wavDataSize, FOURCC_RIFF_TAG);
auto riffChunk = FindChunk(wavData, wavDataSize, wavEnd, FOURCC_RIFF_TAG);
if (!riffChunk || riffChunk->size < 4)
{
return E_FAIL;
@ -347,7 +357,7 @@ namespace
return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF);
}
auto dlsChunk = FindChunk(ptr, riffChunk->size, FOURCC_DLS_SAMPLE);
auto dlsChunk = FindChunk(ptr, riffChunk->size, wavEnd, FOURCC_DLS_SAMPLE);
if (dlsChunk)
{
ptr = reinterpret_cast<const uint8_t*>(dlsChunk) + sizeof(RIFFChunk);
@ -378,7 +388,7 @@ namespace
}
// Locate 'smpl' (Sample Chunk)
auto midiChunk = FindChunk(ptr, riffChunk->size, FOURCC_MIDI_SAMPLE);
auto midiChunk = FindChunk(ptr, riffChunk->size, wavEnd, FOURCC_MIDI_SAMPLE);
if (midiChunk)
{
ptr = reinterpret_cast<const uint8_t*>(midiChunk) + sizeof(RIFFChunk);
@ -434,7 +444,7 @@ namespace
const uint8_t* wavEnd = wavData + wavDataSize;
// Locate RIFF 'WAVE'
auto riffChunk = FindChunk(wavData, wavDataSize, FOURCC_RIFF_TAG);
auto riffChunk = FindChunk(wavData, wavDataSize, wavEnd, FOURCC_RIFF_TAG);
if (!riffChunk || riffChunk->size < 4)
{
return E_FAIL;
@ -453,7 +463,7 @@ namespace
return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF);
}
auto tableChunk = FindChunk(ptr, riffChunk->size, tag);
auto tableChunk = FindChunk(ptr, riffChunk->size, wavEnd, tag);
if (tableChunk)
{
ptr = reinterpret_cast<const uint8_t*>(tableChunk) + sizeof(RIFFChunk);

Просмотреть файл

@ -317,13 +317,53 @@ namespace
switch (d3d10ext->dxgiFormat)
{
case DXGI_FORMAT_NV12:
case DXGI_FORMAT_P010:
case DXGI_FORMAT_P016:
case DXGI_FORMAT_420_OPAQUE:
if ((d3d10ext->resourceDimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D)
|| (width % 2) != 0 || (height % 2) != 0)
{
DebugTrace("ERROR: Video texture does not meet width/height requirements.\n");
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
break;
case DXGI_FORMAT_YUY2:
case DXGI_FORMAT_Y210:
case DXGI_FORMAT_Y216:
case DXGI_FORMAT_P208:
if ((width % 2) != 0)
{
DebugTrace("ERROR: Video texture does not meet width requirements.\n");
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
break;
case DXGI_FORMAT_NV11:
if ((width % 4) != 0)
{
DebugTrace("ERROR: Video texture does not meet width requirements.\n");
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
break;
case DXGI_FORMAT_AI44:
case DXGI_FORMAT_IA44:
case DXGI_FORMAT_P8:
case DXGI_FORMAT_A8P8:
DebugTrace("ERROR: DDSTextureLoader does not support video textures. Consider using DirectXTex instead.\n");
DebugTrace("ERROR: Legacy stream video texture formats are not supported by Direct3D.\n");
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
case DXGI_FORMAT_V208:
if ((d3d10ext->resourceDimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D)
|| (height % 2) != 0)
{
DebugTrace("ERROR: Video texture does not meet height requirements.\n");
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
}
break;
default:
if (BitsPerPixel(d3d10ext->dxgiFormat) == 0)
{

Просмотреть файл

@ -568,15 +568,31 @@ namespace DirectX
case DXGI_FORMAT_NV12:
case DXGI_FORMAT_420_OPAQUE:
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
case DXGI_FORMAT_P208:
#endif
if ((height % 2) != 0)
{
// Requires a height alignment of 2.
return E_INVALIDARG;
}
planar = true;
bpe = 2;
break;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
case DXGI_FORMAT_P208:
planar = true;
bpe = 2;
break;
#endif
case DXGI_FORMAT_P010:
case DXGI_FORMAT_P016:
if ((height % 2) != 0)
{
// Requires a height alignment of 2.
return E_INVALIDARG;
}
planar = true;
bpe = 4;
break;