MCPcopy Create free account
hub / github.com/HiLab-git/SimpleCRF / lodepng_zlib_decompress

Function lodepng_zlib_decompress

dependency/densecrf/examples/lodepng.cpp:2126–2169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2124#ifdef LODEPNG_COMPILE_DECODER
2125
2126unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, const unsigned char* in,
2127 size_t insize, const LodePNGDecompressSettings* settings)
2128{
2129 unsigned error = 0;
2130 unsigned CM, CINFO, FDICT;
2131
2132 if(insize < 2) return 53; /*error, size of zlib data too small*/
2133 /*read information from zlib header*/
2134 if((in[0] * 256 + in[1]) % 31 != 0)
2135 {
2136 /*error: 256 * in[0] + in[1] must be a multiple of 31, the FCHECK value is supposed to be made that way*/
2137 return 24;
2138 }
2139
2140 CM = in[0] & 15;
2141 CINFO = (in[0] >> 4) & 15;
2142 /*FCHECK = in[1] & 31;*/ /*FCHECK is already tested above*/
2143 FDICT = (in[1] >> 5) & 1;
2144 /*FLEVEL = (in[1] >> 6) & 3;*/ /*FLEVEL is not used here*/
2145
2146 if(CM != 8 || CINFO > 7)
2147 {
2148 /*error: only compression method 8: inflate with sliding window of 32k is supported by the PNG spec*/
2149 return 25;
2150 }
2151 if(FDICT != 0)
2152 {
2153 /*error: the specification of PNG says about the zlib stream:
2154 "The additional flags shall not specify a preset dictionary."*/
2155 return 26;
2156 }
2157
2158 error = inflate(out, outsize, in + 2, insize - 2, settings);
2159 if(error) return error;
2160
2161 if(!settings->ignore_adler32)
2162 {
2163 unsigned ADLER32 = lodepng_read32bitInt(&in[insize - 4]);
2164 unsigned checksum = adler32(*out, (unsigned)(*outsize));
2165 if(checksum != ADLER32) return 58; /*error, adler checksum not correct, data must be corrupted*/
2166 }
2167
2168 return 0; /*no error*/
2169}
2170
2171static unsigned zlib_decompress(unsigned char** out, size_t* outsize, const unsigned char* in,
2172 size_t insize, const LodePNGDecompressSettings* settings)

Callers 1

zlib_decompressFunction · 0.85

Calls 3

inflateFunction · 0.85
lodepng_read32bitIntFunction · 0.85
adler32Function · 0.85

Tested by

no test coverage detected