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:
commit
48c48ffd9e
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -76,6 +76,8 @@ int main() {
|
|||
const std::int32_t memorySize = scePngDecQueryMemorySize(¶m);
|
||||
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(¶m, nullptr, static_cast<std::uint32_t>(memorySize), &handle) == invalidAddr);
|
||||
Require(scePngDecCreate(¶m, unaligned, static_cast<std::uint32_t>(memorySize), nullptr) == invalidAddr);
|
||||
Require(scePngDecCreate(¶m, unaligned, static_cast<std::uint32_t>(memorySize) - 1, &handle) == invalidWorkMemory);
|
||||
|
|
|
|||
Loading…
Reference in New Issue