| 2093 | #ifdef LODEPNG_COMPILE_DECODER |
| 2094 | |
| 2095 | unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, const unsigned char* in, |
| 2096 | size_t insize, const LodePNGDecompressSettings* settings) |
| 2097 | { |
| 2098 | unsigned error = 0; |
| 2099 | unsigned CM, CINFO, FDICT; |
| 2100 | |
| 2101 | if(insize < 2) return 53; /*error, size of zlib data too small*/ |
| 2102 | /*read information from zlib header*/ |
| 2103 | if((in[0] * 256 + in[1]) % 31 != 0) |
| 2104 | { |
| 2105 | /*error: 256 * in[0] + in[1] must be a multiple of 31, the FCHECK value is supposed to be made that way*/ |
| 2106 | return 24; |
| 2107 | } |
| 2108 | |
| 2109 | CM = in[0] & 15; |
| 2110 | CINFO = (in[0] >> 4) & 15; |
| 2111 | /*FCHECK = in[1] & 31;*/ /*FCHECK is already tested above*/ |
| 2112 | FDICT = (in[1] >> 5) & 1; |
| 2113 | /*FLEVEL = (in[1] >> 6) & 3;*/ /*FLEVEL is not used here*/ |
| 2114 | |
| 2115 | if(CM != 8 || CINFO > 7) |
| 2116 | { |
| 2117 | /*error: only compression method 8: inflate with sliding window of 32k is supported by the PNG spec*/ |
| 2118 | return 25; |
| 2119 | } |
| 2120 | if(FDICT != 0) |
| 2121 | { |
| 2122 | /*error: the specification of PNG says about the zlib stream: |
| 2123 | "The additional flags shall not specify a preset dictionary."*/ |
| 2124 | return 26; |
| 2125 | } |
| 2126 | |
| 2127 | error = inflate(out, outsize, in + 2, insize - 2, settings); |
| 2128 | if(error) return error; |
| 2129 | |
| 2130 | if(!settings->ignore_adler32) |
| 2131 | { |
| 2132 | unsigned ADLER32 = lodepng_read32bitInt(&in[insize - 4]); |
| 2133 | unsigned checksum = adler32(*out, (unsigned)(*outsize)); |
| 2134 | if(checksum != ADLER32) return 58; /*error, adler checksum not correct, data must be corrupted*/ |
| 2135 | } |
| 2136 | |
| 2137 | return 0; /*no error*/ |
| 2138 | } |
| 2139 | |
| 2140 | static unsigned zlib_decompress(unsigned char** out, size_t* outsize, const unsigned char* in, |
| 2141 | size_t insize, const LodePNGDecompressSettings* settings) |
no test coverage detected