Merge "imgdiff: skip spurious gzip headers in image files"

am: 8e150a5b24

* commit '8e150a5b240833ddf54cbc572cea30ab18e06d86':
  imgdiff: skip spurious gzip headers in image files
This commit is contained in:
David Riley
2016-01-04 18:05:34 +00:00
committed by android-build-merger
+13 -6
View File
@@ -407,6 +407,7 @@ unsigned char* ReadImage(const char* filename,
while (pos < sz) { while (pos < sz) {
unsigned char* p = img+pos; unsigned char* p = img+pos;
bool processed_deflate = false;
if (sz - pos >= 4 && if (sz - pos >= 4 &&
p[0] == 0x1f && p[1] == 0x8b && p[0] == 0x1f && p[1] == 0x8b &&
p[2] == 0x08 && // deflate compression p[2] == 0x08 && // deflate compression
@@ -460,18 +461,24 @@ unsigned char* ReadImage(const char* filename,
strm.next_out = curr->data + curr->len; strm.next_out = curr->data + curr->len;
ret = inflate(&strm, Z_NO_FLUSH); ret = inflate(&strm, Z_NO_FLUSH);
if (ret < 0) { if (ret < 0) {
printf("Error: inflate failed [%s] at file offset [%zu]\n" if (!processed_deflate) {
"imgdiff only supports gzip kernel compression," // This is the first chunk, assume that it's just a spurious
" did you try CONFIG_KERNEL_LZO?\n", // gzip header instead of a real one.
strm.msg, chunk_offset); break;
free(img); }
return NULL; printf("Error: inflate failed [%s] at file offset [%zu]\n"
"imgdiff only supports gzip kernel compression,"
" did you try CONFIG_KERNEL_LZO?\n",
strm.msg, chunk_offset);
free(img);
return NULL;
} }
curr->len = allocated - strm.avail_out; curr->len = allocated - strm.avail_out;
if (strm.avail_out == 0) { if (strm.avail_out == 0) {
allocated *= 2; allocated *= 2;
curr->data = reinterpret_cast<unsigned char*>(realloc(curr->data, allocated)); curr->data = reinterpret_cast<unsigned char*>(realloc(curr->data, allocated));
} }
processed_deflate = true;
} while (ret != Z_STREAM_END); } while (ret != Z_STREAM_END);
curr->deflate_len = sz - strm.avail_in - pos; curr->deflate_len = sz - strm.avail_in - pos;