diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2018-12-16 23:56:13 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2018-12-16 23:56:13 +0000 |
commit | b288a1ad383a71f61df18432d0a260e7ca03a650 (patch) | |
tree | b7b88ad3c3d48062ffa801ec6444f58c60696fd0 | |
parent | 7424993d11fd3b9050c01a7f214fd3b7bf41d292 (diff) | |
download | netpbm-mirror-b288a1ad383a71f61df18432d0a260e7ca03a650.tar.gz netpbm-mirror-b288a1ad383a71f61df18432d0a260e7ca03a650.tar.xz netpbm-mirror-b288a1ad383a71f61df18432d0a260e7ca03a650.zip |
Fix use of unset variable with a truecolor OS/2 BMP, possibly causing incorrect interpretation of pixels
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3457 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r-- | converter/other/bmptopnm.c | 125 | ||||
-rw-r--r-- | doc/HISTORY | 5 |
2 files changed, 85 insertions, 45 deletions
diff --git a/converter/other/bmptopnm.c b/converter/other/bmptopnm.c index 8573a9d0..3f66634b 100644 --- a/converter/other/bmptopnm.c +++ b/converter/other/bmptopnm.c @@ -250,6 +250,49 @@ GetCieXyzTriple(FILE * const ifP) { +static struct pixelformat +defaultPixelformat(unsigned int const bitCount) { + + struct pixelformat retval; + + switch (bitCount) { + case 16: + /* This layout is sometimes called "RGB555". A document from + Microsoft says this is the default (when the "compression" + field of the header says COMP_BITFIELDS). + */ + retval.conventionalBgr = FALSE; + retval.red.shift = 10; + retval.grn.shift = 5; + retval.blu.shift = 0; + retval.trn.shift = 0; + retval.red.mask = 0x1f; /* 5 bits */ + retval.grn.mask = 0x1f; /* 5 bits */ + retval.blu.mask = 0x1f; /* 5 bits */ + retval.trn.mask = 0; + break; + case 24: + case 32: + retval.conventionalBgr = TRUE; + retval.red.shift = 16; + retval.grn.shift = 8; + retval.blu.shift = 0; + retval.trn.shift = 0; + retval.red.mask = 0xff; /* 8 bits */ + retval.grn.mask = 0xff; /* 8 bits */ + retval.blu.mask = 0xff; /* 8 bits */ + retval.trn.mask = 0; + break; + default: + /* colormapped - masks are undefined */ + break; + } + + return retval; +} + + + static void readOffBytes(FILE * const fp, unsigned int const nbytes) { /*---------------------------------------------------------------------------- @@ -299,7 +342,21 @@ bmpReadfileheader(FILE * const ifP, static void readOs2InfoHeaderRest(FILE * const ifP, struct bmpInfoHeader * const headerP) { +/*---------------------------------------------------------------------------- + Read the rest of the info header, after its size field, of an OS2 BMP from + *ifP. + Add the information from it to *headerP, in particular these members: + + cols + rows + rowOrder + cPlanes + cBitCount + cmapSize + pixelformat + compression +-----------------------------------------------------------------------------*/ unsigned short colsField, rowsField; unsigned short planesField, bitCountField; @@ -337,6 +394,8 @@ readOs2InfoHeaderRest(FILE * const ifP, pm_error("Unrecognized bits per pixel in OS/2 BMP file header: %d", headerP->cBitCount); + headerP->pixelformat = defaultPixelformat(headerP->cBitCount); + headerP->compression = BMPCOMP_RGB; } @@ -525,49 +584,6 @@ computeConventionalBgr(struct pixelformat * const fP, -static struct pixelformat -defaultPixelformat(unsigned int const bitCount) { - - struct pixelformat retval; - - switch (bitCount) { - case 16: - /* This layout is sometimes called "RGB555". A document from - Microsoft says this is the default (when the "compression" - field of the header says COMP_BITFIELDS). - */ - retval.conventionalBgr = FALSE; - retval.red.shift = 10; - retval.grn.shift = 5; - retval.blu.shift = 0; - retval.trn.shift = 0; - retval.red.mask = 0x1f; /* 5 bits */ - retval.grn.mask = 0x1f; /* 5 bits */ - retval.blu.mask = 0x1f; /* 5 bits */ - retval.trn.mask = 0; - break; - case 24: - case 32: - retval.conventionalBgr = TRUE; - retval.red.shift = 16; - retval.grn.shift = 8; - retval.blu.shift = 0; - retval.trn.shift = 0; - retval.red.mask = 0xff; /* 8 bits */ - retval.grn.mask = 0xff; /* 8 bits */ - retval.blu.mask = 0xff; /* 8 bits */ - retval.trn.mask = 0; - break; - default: - /* colormapped - masks are undefined */ - break; - } - - return retval; -} - - - static void readV4InfoHeaderExtension(FILE * const ifP, struct bmpInfoHeader * const headerP, @@ -636,7 +652,28 @@ static void readWindowsInfoHeaderRest(FILE * const ifP, unsigned int const cInfoHeaderSize, struct bmpInfoHeader * const headerP) { - +/*---------------------------------------------------------------------------- + Read the rest of the info header, after the length field, of a Windows BMP + from *ifP. + + 'cInfoHeaderSize' is the size of the info header, not counting its size + field. Note that besides telling us how much data to read, this also + implies which of the three major formats the data is in. + + Add the information from it to *headerP, in particular these members: + + cols + rows + rowOrder + cPlanes + cBitCount + bitFields + compression + imageSize + cmapSize + pixelformat + endPoints +-----------------------------------------------------------------------------*/ /* There are 3 major formats of Windows BMP, identified by the 3 info header lengths. The original one is 40 bytes. The "V4 header" is 108 bytes and was diff --git a/doc/HISTORY b/doc/HISTORY index d9dbea55..4faaed7d 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -38,8 +38,11 @@ not yet BJH Release 10.85.00 programs work (function previously omitted by design because it was too hard). + bmptopnm: Fix wrong output for non-colormapped OS2 BMP. Broken + in Netpbm 10.18 (September 2003). + bmptopnm: Fix array bounds violation when index value in raster - is too big. Broken after Netpbm 10.10 (October 2002) but before + is too big. Broken after Netpbm 10.11 (October 2002) but before 10.19 (November 2003). libnetpbm: Fix invalid memory reference in color name processing |