MCPcopy Create free account
hub / github.com/DFHack/dfhack / inflateNoCompression

Function inflateNoCompression

depends/lodepng/lodepng.cpp:1356–1386  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1354}
1355
1356static unsigned inflateNoCompression(ucvector* out, LodePNGBitReader* reader,
1357 const LodePNGDecompressSettings* settings) {
1358 size_t bytepos;
1359 size_t size = reader->size;
1360 unsigned LEN, NLEN, error = 0;
1361
1362 /*go to first boundary of byte*/
1363 bytepos = (reader->bp + 7u) >> 3u;
1364
1365 /*read LEN (2 bytes) and NLEN (2 bytes)*/
1366 if(bytepos + 4 >= size) return 52; /*error, bit pointer will jump past memory*/
1367 LEN = (unsigned)reader->data[bytepos] + ((unsigned)reader->data[bytepos + 1] << 8u); bytepos += 2;
1368 NLEN = (unsigned)reader->data[bytepos] + ((unsigned)reader->data[bytepos + 1] << 8u); bytepos += 2;
1369
1370 /*check if 16-bit NLEN is really the one's complement of LEN*/
1371 if(!settings->ignore_nlen && LEN + NLEN != 65535) {
1372 return 21; /*error: NLEN is not one's complement of LEN*/
1373 }
1374
1375 if(!ucvector_resize(out, out->size + LEN)) return 83; /*alloc fail*/
1376
1377 /*read the literal data: LEN bytes are now stored in the out buffer*/
1378 if(bytepos + LEN > size) return 23; /*error: reading outside of in buffer*/
1379
1380 lodepng_memcpy(out->data + out->size - LEN, reader->data + bytepos, LEN);
1381 bytepos += LEN;
1382
1383 reader->bp = bytepos << 3u;
1384
1385 return error;
1386}
1387
1388static unsigned lodepng_inflatev(ucvector* out,
1389 const unsigned char* in, size_t insize,

Callers 1

lodepng_inflatevFunction · 0.85

Calls 2

ucvector_resizeFunction · 0.85
lodepng_memcpyFunction · 0.85

Tested by

no test coverage detected