From 7800bbce74accaeeb8dc0f9c5deaa86ff8683421 Mon Sep 17 00:00:00 2001 From: dborth Date: Tue, 17 Mar 2009 06:06:01 +0000 Subject: [PATCH] safer PNG handling --- source/ngc/gui/gui_imagedata.cpp | 37 ++++++++++++++++++++++++-------- source/ngc/menu.cpp | 2 +- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/source/ngc/gui/gui_imagedata.cpp b/source/ngc/gui/gui_imagedata.cpp index 1bf9c21..23f29e7 100644 --- a/source/ngc/gui/gui_imagedata.cpp +++ b/source/ngc/gui/gui_imagedata.cpp @@ -24,16 +24,35 @@ GuiImageData::GuiImageData(const u8 * img) else { PNGUPROP imgProp; - IMGCTX ctx; + IMGCTX ctx = PNGU_SelectImageFromBuffer(img); - ctx = PNGU_SelectImageFromBuffer(img); - PNGU_GetImageProperties (ctx, &imgProp); - width = imgProp.imgWidth; - height = imgProp.imgHeight; - data = (u8 *)memalign (32, imgProp.imgWidth * imgProp.imgHeight * 4); - PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, data, 255); - int len = imgProp.imgWidth * imgProp.imgHeight * 4; - DCFlushRange(data, len+len%32); + if(!ctx) + return; + + int res = PNGU_GetImageProperties(ctx, &imgProp); + + if(res == PNGU_OK) + { + data = (u8 *)memalign (32, imgProp.imgWidth * imgProp.imgHeight * 4); + + if(data) + { + res = PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, data, 255); + + if(res == PNGU_OK) + { + width = imgProp.imgWidth; + height = imgProp.imgHeight; + int len = imgProp.imgWidth * imgProp.imgHeight * 4; + DCFlushRange(data, len+len%32); + } + else + { + free(data); + data = NULL; + } + } + } PNGU_ReleaseImageContext (ctx); } } diff --git a/source/ngc/menu.cpp b/source/ngc/menu.cpp index 1154a09..2383326 100644 --- a/source/ngc/menu.cpp +++ b/source/ngc/menu.cpp @@ -3264,7 +3264,7 @@ MainMenu (int menu) GuiImage logoImgOver(&logoOver); btnLogo = new GuiButton(logoImg.GetWidth(), logoImg.GetHeight()); btnLogo->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - btnLogo->SetPosition(-50, 30); + btnLogo->SetPosition(-30, 30); btnLogo->SetImage(&logoImg); btnLogo->SetImageOver(&logoImgOver); btnLogo->SetTrigger(&trigA);