From 9ef4859f55ef9d3fc324aeb22deaa190c798cdde Mon Sep 17 00:00:00 2001 From: Laurens Voerman Date: Thu, 24 Aug 2017 11:33:23 +0200 Subject: [PATCH] fix gcc/VC compile warnings, reject color mapped tga files with missing colormap. --- src/osgPlugins/tga/ReaderWriterTGA.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/osgPlugins/tga/ReaderWriterTGA.cpp b/src/osgPlugins/tga/ReaderWriterTGA.cpp index af3b789c7..b1e3ad6a4 100644 --- a/src/osgPlugins/tga/ReaderWriterTGA.cpp +++ b/src/osgPlugins/tga/ReaderWriterTGA.cpp @@ -273,8 +273,8 @@ int *numComponents_ret) int flags; int format; unsigned char *colormap; - int colormapLen; - int indexsize; + int colormapLen = 0; + int indexsize = 0; int rleIsCompressed; int rleRemaining; int rleEntrySize; @@ -360,6 +360,10 @@ int *numComponents_ret) { case 1: /* colormap, uncompressed */ { + if (colormapLen == 0 || indexsize == 0) { + tgaerror = ERR_UNSUPPORTED; /* colormap missing or empty */ + return NULL; + } unsigned char * formattedMap = new unsigned char[colormapLen * format]; for (int i = 0; i < colormapLen; i++) { @@ -395,7 +399,7 @@ int *numComponents_ret) break; default: tgaerror = ERR_UNSUPPORTED; - break; + return NULL; /* unreachable code - (depth < 1 || depth > 4) rejected by "check for reasonable values in case this is not a tga file" near the start of this function*/ } int adjustedX = bLeftToRight ? x : (width - 1) - x;