| 1223 | } |
| 1224 | |
| 1225 | static unsigned inflateNoCompression(ucvector* out, const unsigned char* in, size_t* bp, size_t* pos, size_t inlength) |
| 1226 | { |
| 1227 | size_t p; |
| 1228 | unsigned LEN, NLEN, n, error = 0; |
| 1229 | |
| 1230 | /*go to first boundary of byte*/ |
| 1231 | while(((*bp) & 0x7) != 0) ++(*bp); |
| 1232 | p = (*bp) / 8; /*byte position*/ |
| 1233 | |
| 1234 | /*read LEN (2 bytes) and NLEN (2 bytes)*/ |
| 1235 | if(p + 4 >= inlength) return 52; /*error, bit pointer will jump past memory*/ |
| 1236 | LEN = in[p] + 256u * in[p + 1]; p += 2; |
| 1237 | NLEN = in[p] + 256u * in[p + 1]; p += 2; |
| 1238 | |
| 1239 | /*check if 16-bit NLEN is really the one's complement of LEN*/ |
| 1240 | if(LEN + NLEN != 65535) return 21; /*error: NLEN is not one's complement of LEN*/ |
| 1241 | |
| 1242 | if(!ucvector_resize(out, (*pos) + LEN)) return 83; /*alloc fail*/ |
| 1243 | |
| 1244 | /*read the literal data: LEN bytes are now stored in the out buffer*/ |
| 1245 | if(p + LEN > inlength) return 23; /*error: reading outside of in buffer*/ |
| 1246 | for(n = 0; n < LEN; ++n) out->data[(*pos)++] = in[p++]; |
| 1247 | |
| 1248 | (*bp) = p * 8; |
| 1249 | |
| 1250 | return error; |
| 1251 | } |
| 1252 | |
| 1253 | static unsigned lodepng_inflatev(ucvector* out, |
| 1254 | const unsigned char* in, size_t insize, |
no test coverage detected