expected_size is expected output size, to avoid intermediate allocations. Set to 0 if not known. */
| 2224 | |
| 2225 | /*expected_size is expected output size, to avoid intermediate allocations. Set to 0 if not known. */ |
| 2226 | static unsigned zlib_decompress(unsigned char** out, size_t* outsize, size_t expected_size, |
| 2227 | const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) { |
| 2228 | unsigned error; |
| 2229 | if(settings->custom_zlib) { |
| 2230 | error = settings->custom_zlib(out, outsize, in, insize, settings); |
| 2231 | if(error) { |
| 2232 | /*the custom zlib is allowed to have its own error codes, however, we translate it to code 110*/ |
| 2233 | error = 110; |
| 2234 | /*if there's a max output size, and the custom zlib returned error, then indicate that error instead*/ |
| 2235 | if(settings->max_output_size && *outsize > settings->max_output_size) error = 109; |
| 2236 | } |
| 2237 | } else { |
| 2238 | ucvector v = ucvector_init(*out, *outsize); |
| 2239 | if(expected_size) { |
| 2240 | /*reserve the memory to avoid intermediate reallocations*/ |
| 2241 | ucvector_resize(&v, *outsize + expected_size); |
| 2242 | v.size = *outsize; |
| 2243 | } |
| 2244 | error = lodepng_zlib_decompressv(&v, in, insize, settings); |
| 2245 | *out = v.data; |
| 2246 | *outsize = v.size; |
| 2247 | } |
| 2248 | return error; |
| 2249 | } |
| 2250 | |
| 2251 | #endif /*LODEPNG_COMPILE_DECODER*/ |
| 2252 |
no test coverage detected