MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / inflateNoCompression

Function inflateNoCompression

src/lodepng.cpp:1186–1214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1184}
1185
1186static unsigned inflateNoCompression(ucvector* out, const unsigned char* in, size_t* bp, size_t* pos, size_t inlength)
1187{
1188 /*go to first boundary of byte*/
1189 size_t p;
1190 unsigned LEN, NLEN, n, error = 0;
1191 while(((*bp) & 0x7) != 0) (*bp)++;
1192 p = (*bp) / 8; /*byte position*/
1193
1194 /*read LEN (2 bytes) and NLEN (2 bytes)*/
1195 if(p >= inlength - 4) return 52; /*error, bit pointer will jump past memory*/
1196 LEN = in[p] + 256 * in[p + 1]; p += 2;
1197 NLEN = in[p] + 256 * in[p + 1]; p += 2;
1198
1199 /*check if 16-bit NLEN is really the one's complement of LEN*/
1200 if(LEN + NLEN != 65535) return 21; /*error: NLEN is not one's complement of LEN*/
1201
1202 if((*pos) + LEN >= out->size)
1203 {
1204 if(!ucvector_resize(out, (*pos) + LEN)) return 83; /*alloc fail*/
1205 }
1206
1207 /*read the literal data: LEN bytes are now stored in the out buffer*/
1208 if(p + LEN > inlength) return 23; /*error: reading outside of in buffer*/
1209 for(n = 0; n < LEN; n++) out->data[(*pos)++] = in[p++];
1210
1211 (*bp) = p * 8;
1212
1213 return error;
1214}
1215
1216static unsigned lodepng_inflatev(ucvector* out,
1217 const unsigned char* in, size_t insize,

Callers 1

lodepng_inflatevFunction · 0.85

Calls 1

ucvector_resizeFunction · 0.85

Tested by

no test coverage detected