| 2069 | #ifdef LODEPNG_COMPILE_DECODER |
| 2070 | |
| 2071 | unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, const unsigned char* in, |
| 2072 | size_t insize, const LodePNGDecompressSettings* settings) |
| 2073 | { |
| 2074 | unsigned error = 0; |
| 2075 | unsigned CM, CINFO, FDICT; |
| 2076 | |
| 2077 | if(insize < 2) return 53; /*error, size of zlib data too small*/ |
| 2078 | /*read information from zlib header*/ |
| 2079 | if((in[0] * 256 + in[1]) % 31 != 0) |
| 2080 | { |
| 2081 | /*error: 256 * in[0] + in[1] must be a multiple of 31, the FCHECK value is supposed to be made that way*/ |
| 2082 | return 24; |
| 2083 | } |
| 2084 | |
| 2085 | CM = in[0] & 15; |
| 2086 | CINFO = (in[0] >> 4) & 15; |
| 2087 | /*FCHECK = in[1] & 31;*/ /*FCHECK is already tested above*/ |
| 2088 | FDICT = (in[1] >> 5) & 1; |
| 2089 | /*FLEVEL = (in[1] >> 6) & 3;*/ /*FLEVEL is not used here*/ |
| 2090 | |
| 2091 | if(CM != 8 || CINFO > 7) |
| 2092 | { |
| 2093 | /*error: only compression method 8: inflate with sliding window of 32k is supported by the PNG spec*/ |
| 2094 | return 25; |
| 2095 | } |
| 2096 | if(FDICT != 0) |
| 2097 | { |
| 2098 | /*error: the specification of PNG says about the zlib stream: |
| 2099 | "The additional flags shall not specify a preset dictionary."*/ |
| 2100 | return 26; |
| 2101 | } |
| 2102 | |
| 2103 | error = inflate(out, outsize, in + 2, insize - 2, settings); |
| 2104 | if(error) return error; |
| 2105 | |
| 2106 | if(!settings->ignore_adler32) |
| 2107 | { |
| 2108 | unsigned ADLER32 = lodepng_read32bitInt(&in[insize - 4]); |
| 2109 | unsigned checksum = adler32(*out, (unsigned)(*outsize)); |
| 2110 | if(checksum != ADLER32) return 58; /*error, adler checksum not correct, data must be corrupted*/ |
| 2111 | } |
| 2112 | |
| 2113 | return 0; /*no error*/ |
| 2114 | } |
| 2115 | |
| 2116 | static unsigned zlib_decompress(unsigned char** out, size_t* outsize, const unsigned char* in, |
| 2117 | size_t insize, const LodePNGDecompressSettings* settings) |
no test coverage detected