From 53ba375fbf20d62bb6feec7dac2036035367d7ab Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Wed, 8 Nov 2023 18:20:40 -0800 Subject: [PATCH] texconv: Fix PPM reader to avoid overread of buffer (#410) --- .gitignore | 1 + Texconv/PortablePixMap.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 56c7697..8e9cf76 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ Profile Release x64 /Tests +/Testing /wiki /out /CMakeUserPresets.json diff --git a/Texconv/PortablePixMap.cpp b/Texconv/PortablePixMap.cpp index f5b4d8d..870bba8 100644 --- a/Texconv/PortablePixMap.cpp +++ b/Texconv/PortablePixMap.cpp @@ -202,16 +202,17 @@ HRESULT __cdecl LoadFromPortablePixMap( while (ppmSize > 0 && (pixels < pixelEnd)) { + if (ppmSize < 3) + { + return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF); + } + *pixels++ = (255 * pData[0] / max) | ((255 * pData[1] / max) << 8) | ((255 * pData[2] / max) << 16) | 0xff000000; pData += 3; - if (ppmSize < 3) - { - return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF); - } ppmSize -= 3; }