aboutsummaryrefslogtreecommitdiff
path: root/lib/Support/Compressor.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2005-05-13 07:05:37 +0000
committerReid Spencer <rspencer@reidspencer.com>2005-05-13 07:05:37 +0000
commitfe07581d789c0a1b329dd8956e3b68e71ae9fcfa (patch)
tree4e0c84c67620876025b4807685a555c5b793df73 /lib/Support/Compressor.cpp
parentefd9168eae647b3a52d5acef04d9e042d00f2ea3 (diff)
Make sure that decompression checks for the case that bzip2 returns
BZ_OK (meaning more data is expected) but there is no more input data. In this case, the input file is probably truncated. Generate an exception that indicates this case when its detected. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21926 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Compressor.cpp')
-rw-r--r--lib/Support/Compressor.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/Support/Compressor.cpp b/lib/Support/Compressor.cpp
index d2dc5e50ab..e0f5f29aad 100644
--- a/lib/Support/Compressor.cpp
+++ b/lib/Support/Compressor.cpp
@@ -408,7 +408,8 @@ size_t Compressor::decompress(const char *in, size_t size,
// Decompress it
int bzerr = BZ_OK;
- while (BZ_OK == (bzerr = BZ2_bzDecompress(&bzdata))) {
+ while ( BZ_OK == (bzerr = BZ2_bzDecompress(&bzdata)) &&
+ bzdata.avail_in != 0 ) {
if (0 != getdata_uns(bzdata.next_out, bzdata.avail_out,cb,context)) {
BZ2_bzDecompressEnd(&bzdata);
throw std::string("Can't allocate output buffer");
@@ -420,11 +421,12 @@ size_t Compressor::decompress(const char *in, size_t size,
case BZ_MEM_ERROR: throw std::string("Out of memory");
case BZ_DATA_ERROR: throw std::string("Data integrity error");
case BZ_DATA_ERROR_MAGIC:throw std::string("Data is not BZIP2");
+ case BZ_OK: throw std::string("Insufficient input for bzip2");
+ case BZ_STREAM_END: break;
default: throw("Ooops");
- case BZ_STREAM_END:
- break;
}
+
// Finish
result = bzdata.total_out_lo32;
if (sizeof(size_t) == sizeof(uint64_t))
@@ -474,7 +476,7 @@ Compressor::decompressToStream(const char*in, size_t size, std::ostream& out){
// Set up the context and writer
WriterContext ctxt(&out,size / 2);
- // Compress everything after the magic number (which we'll alter)
+ // Decompress everything after the magic number (which we'll alter)
size_t zipSize = Compressor::decompress(in,size,
WriterContext::callback, (void*)&ctxt);