Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8e150a5b authored by David Riley's avatar David Riley Committed by Gerrit Code Review
Browse files

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

parents 29b0fbe1 0779fc98
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -407,6 +407,7 @@ unsigned char* ReadImage(const char* filename,
  while (pos < sz) {
    unsigned char* p = img+pos;

    bool processed_deflate = false;
    if (sz - pos >= 4 &&
        p[0] == 0x1f && p[1] == 0x8b &&
        p[2] == 0x08 &&    // deflate compression
@@ -460,6 +461,11 @@ unsigned char* ReadImage(const char* filename,
        strm.next_out = curr->data + curr->len;
        ret = inflate(&strm, Z_NO_FLUSH);
        if (ret < 0) {
          if (!processed_deflate) {
            // This is the first chunk, assume that it's just a spurious
            // gzip header instead of a real one.
            break;
          }
          printf("Error: inflate failed [%s] at file offset [%zu]\n"
                 "imgdiff only supports gzip kernel compression,"
                 " did you try CONFIG_KERNEL_LZO?\n",
@@ -472,6 +478,7 @@ unsigned char* ReadImage(const char* filename,
          allocated *= 2;
          curr->data = reinterpret_cast<unsigned char*>(realloc(curr->data, allocated));
        }
        processed_deflate = true;
      } while (ret != Z_STREAM_END);

      curr->deflate_len = sz - strm.avail_in - pos;