Merge pull request #4390 from ErenYeager1836/fix/pngdec-validate-size-and-max-width

fix(libScePngDec): validate this_size on create
This commit is contained in:
Dean 2026-10-13 22:00:41 +13:00 committed by GitHub
commit 48c48ffd9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 0 deletions

View File

@ -55,6 +55,7 @@ static_assert(sizeof(Context) + HANDLE_ALIGNMENT - 1 <= MEMORY_SIZE);
std::int32_t validateCreateParam(const PngDecCreateParam* param) {
if (!param) return SCE_PNG_DEC_ERROR_INVALID_PARAM;
if (param->this_size != sizeof(PngDecCreateParam)) return SCE_PNG_DEC_ERROR_INVALID_SIZE;
if (param->attribute != ATTRIBUTE_NONE && param->attribute != ATTRIBUTE_BIT_DEPTH_16) return SCE_PNG_DEC_ERROR_INVALID_PARAM;
if (param->max_image_width == 0 || param->max_image_width - 1 > MAX_IMAGE_WIDTH) return SCE_PNG_DEC_ERROR_INVALID_SIZE;
return 0;

View File

@ -76,6 +76,8 @@ int main() {
const std::int32_t memorySize = scePngDecQueryMemorySize(&param);
Require(memorySize > 0);
Require(scePngDecQueryMemorySize(nullptr) == invalidParam);
const PngDecCreateParam badSize{sizeof(PngDecCreateParam) - 1, 0, 1920};
Require(scePngDecQueryMemorySize(&badSize) == invalidSize);
const PngDecCreateParam badAttribute{sizeof(PngDecCreateParam), 2, 1920};
Require(scePngDecQueryMemorySize(&badAttribute) == invalidParam);
const PngDecCreateParam zeroWidth{sizeof(PngDecCreateParam), 0, 0};
@ -89,6 +91,7 @@ int main() {
unsigned char* unaligned = memory.data() + 1;
void* handle = nullptr;
Require(scePngDecCreate(nullptr, unaligned, static_cast<std::uint32_t>(memorySize), &handle) == invalidParam);
Require(scePngDecCreate(&badSize, unaligned, static_cast<std::uint32_t>(memorySize), &handle) == invalidSize);
Require(scePngDecCreate(&param, nullptr, static_cast<std::uint32_t>(memorySize), &handle) == invalidAddr);
Require(scePngDecCreate(&param, unaligned, static_cast<std::uint32_t>(memorySize), nullptr) == invalidAddr);
Require(scePngDecCreate(&param, unaligned, static_cast<std::uint32_t>(memorySize) - 1, &handle) == invalidWorkMemory);