From e787805b8157075041216f563a0e772fd9c85509 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Thu, 21 Dec 2000 12:53:58 +0000 Subject: [PATCH] Extended gzip signature to 3 bytes. committer: mfx 977403238 +0000 --- src/p_vmlinz.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/p_vmlinz.cpp b/src/p_vmlinz.cpp index 0e97d407..c0cf7122 100644 --- a/src/p_vmlinz.cpp +++ b/src/p_vmlinz.cpp @@ -126,20 +126,26 @@ int PackVmlinuzI386::uncompressKernel() // estimate gzip-uncompressed kernel size & alloc buffer ibuf.alloc((file_size - setup_size) * 3); - // find gzip/zlib header for (int gzoff = setup_size; gzoff < file_size; gzoff++) { - int off = find(obuf + gzoff, file_size - gzoff, "\x1F\x8B", 2); + // find gzip header (2 bytes magic, 1 byte method "deflated") + int off = find(obuf + gzoff, file_size - gzoff, "\x1F\x8B\x08", 3); if (off < 0) break; gzoff += off; + // try to decompress fi->seek(gzoff, SEEK_SET); gzFile zf = gzdopen(fi->getFd(), "r"); if (zf == 0) break; int klen = gzread(zf, ibuf, ibuf.getSize()); - if (klen >= file_size) - return klen; + if (klen <= file_size) + continue; + + // FIXME: check for special magic bytes in ibuf ??? + // FIXME: check for kernel architecture ??? + // FIXME: check for special klen size, e.g. (klen & 0xfff) == 0 ??? + return klen; } return 0; @@ -159,6 +165,7 @@ void PackVmlinuzI386::readKernel() // copy the setup boot code setup_buf.alloc(setup_size); memcpy(setup_buf, obuf, setup_size); + //OutputFile::dump("setup.img", setup_buf, setup_size); obuf.free(); obuf.allocForCompression(klen);