Bug 847479 - Add buffer length information when initializing a SeekableZStream. r=nfroyd
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 06 Mar 2013 07:29:05 +0100
changeset 123905 0effb755bdbebf01a94d0a3886679cc84766397c
parent 123904 e50acdd4ea4b01c8b04a014f33aa4ade95d191d4
child 123906 c6b328fb4f3ec9f8e0efec2f9a543a6f40b9d1b9
push id24401
push useremorley@mozilla.com
push dateWed, 06 Mar 2013 16:09:28 +0000
treeherdermozilla-central@635f2c7660c8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnfroyd
bugs847479
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 847479 - Add buffer length information when initializing a SeekableZStream. r=nfroyd
mozglue/linker/Mappable.cpp
mozglue/linker/SeekableZStream.cpp
mozglue/linker/SeekableZStream.h
--- a/mozglue/linker/Mappable.cpp
+++ b/mozglue/linker/Mappable.cpp
@@ -126,17 +126,17 @@ MappableExtractFile::Create(const char *
     }
     if (zStream.total_out != stream->GetUncompressedSize()) {
       log("File not fully uncompressed! %ld / %d", zStream.total_out,
           static_cast<unsigned int>(stream->GetUncompressedSize()));
       return NULL;
     }
   } else if (stream->GetType() == Zip::Stream::STORE) {
     SeekableZStream zStream;
-    if (!zStream.Init(stream->GetBuffer())) {
+    if (!zStream.Init(stream->GetBuffer(), stream->GetSize())) {
       log("Couldn't initialize SeekableZStream for %s", name);
       return NULL;
     }
     if (ftruncate(fd, zStream.GetUncompressedSize()) == -1) {
       log("Couldn't ftruncate %s to decompress library", file.get());
       return NULL;
     }
     MappedPtr buffer(::mmap(NULL, zStream.GetUncompressedSize(), PROT_WRITE,
@@ -348,17 +348,17 @@ MappableSeekableZStream::Create(const ch
 {
   MOZ_ASSERT(stream->GetType() == Zip::Stream::STORE);
   mozilla::ScopedDeletePtr<MappableSeekableZStream> mappable;
   mappable = new MappableSeekableZStream(zip);
 
   if (pthread_mutex_init(&mappable->mutex, NULL))
     return NULL;
 
-  if (!mappable->zStream.Init(stream->GetBuffer()))
+  if (!mappable->zStream.Init(stream->GetBuffer(), stream->GetSize()))
     return NULL;
 
   mappable->buffer = _MappableBuffer::Create(name,
                               mappable->zStream.GetUncompressedSize());
   if (!mappable->buffer)
     return NULL;
 
   mappable->chunkAvail = new unsigned char[mappable->zStream.GetChunksNum()];
--- a/mozglue/linker/SeekableZStream.cpp
+++ b/mozglue/linker/SeekableZStream.cpp
@@ -10,17 +10,17 @@
 #define PAGE_SIZE 4096
 #endif
 
 #ifndef PAGE_MASK
 #define PAGE_MASK (~ (PAGE_SIZE - 1))
 #endif
 
 bool
-SeekableZStream::Init(const void *buf)
+SeekableZStream::Init(const void *buf, size_t length)
 {
   const SeekableZStreamHeader *header = SeekableZStreamHeader::validate(buf);
   if (!header) {
     log("Not a seekable zstream");
     return false;
   }
 
   buffer = reinterpret_cast<const unsigned char *>(buf);
@@ -30,17 +30,18 @@ SeekableZStream::Init(const void *buf)
   offsetTable.Init(&header[1], header->nChunks);
 
   /* Sanity check */
   if ((chunkSize == 0) ||
       (chunkSize % PAGE_SIZE) ||
       (chunkSize > 8 * PAGE_SIZE) ||
       (offsetTable.numElements() < 1) ||
       (lastChunkSize == 0) ||
-      (lastChunkSize > chunkSize)) {
+      (lastChunkSize > chunkSize) ||
+      (length < totalSize)) {
     log("Malformed or broken seekable zstream");
     return false;
   }
 
   return true;
 }
 
 bool
--- a/mozglue/linker/SeekableZStream.h
+++ b/mozglue/linker/SeekableZStream.h
@@ -47,17 +47,17 @@ MOZ_STATIC_ASSERT(sizeof(SeekableZStream
 
 /**
  * Helper class used to decompress Seekable ZStreams.
  */
 class SeekableZStream {
 public:
   /* Initialize from the given buffer. Returns whether initialization
    * succeeded (true) or failed (false). */
-  bool Init(const void *buf);
+  bool Init(const void *buf, size_t length);
 
   /* Decompresses starting from the given chunk. The decompressed data is
    * stored at the given location. The given length, in bytes, indicates
    * how much data to decompress. If length is 0, then exactly one chunk
    * is decompressed.
    * Returns whether decompression succeeded (true) or failed (false). */
   bool Decompress(void *where, size_t chunk, size_t length = 0);