X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fstreams-jar.cpp;h=e597822e9280a426778ec16f0986fa8331d708ff;hb=2d5f45472d142796f87b8b737cc0b56fc9de3bf7;hp=ffaccc2e4a1726bad93186634fe8bdfa3d522f44;hpb=6b15695578f07a3f72c4c9475c1a261a3021472a;p=inkscape.git diff --git a/src/streams-jar.cpp b/src/streams-jar.cpp index ffaccc2e4..e597822e9 100644 --- a/src/streams-jar.cpp +++ b/src/streams-jar.cpp @@ -1,3 +1,4 @@ +#include #include "streams-jar.h" namespace Inkscape { @@ -16,27 +17,16 @@ void JarBuffer::consume_header() throw(JarHeaderException) check_signature(data); _urihandle->read(data+4, 26); compressed_size = compressed_left = unpack_4bytes(data, LOC_CSIZE); - guint16 filename_length = unpack_2bytes(data, LOC_FNLEN); eflen = unpack_2bytes(data, LOC_EFLEN); flags = unpack_2bytes(data, LOC_EXTRA); method = unpack_2bytes(data, LOC_COMP); -#ifdef DEBUG_STREAMS +#ifdef DEBUG_STREAMS std::printf("Compressed size is %u\n", compressed_size); - std::printf("Filename length is %hu\n", filename_length); std::printf("Extra field length is %hu\n", eflen); std::printf("Flags are %#hx\n", flags); std::printf("Compression method is %#hx\n", method); #endif - - //guint32 crc = check_crc(data, flags); - gchar filename[filename_length+1]; - _urihandle->read(filename, filename_length); - filename[filename_length] = '\0'; - -#ifdef DEBUG_STREAMS - std::printf("Filename is %s\n", filename); -#endif } catch (std::exception& e) { throw JarHeaderException(); @@ -75,12 +65,12 @@ void JarBuffer::reset()//resets zlib and buffer (also skips archived directories int JarBuffer::consume_and_inflate() { int nbytes; - + reset(); - nbytes = compressed_left > BUFSIZE_STREAM ? BUFSIZE_STREAM + nbytes = compressed_left > BUFSIZE_STREAM ? BUFSIZE_STREAM : compressed_left; - + if (is_compressed()) return consume_compressed(nbytes); else @@ -89,27 +79,26 @@ int JarBuffer::consume_and_inflate() int JarBuffer::consume_compressed(int nbytes) { - int ret; + int ret=do_consume_and_inflate(nbytes); - if ((ret = do_consume_and_inflate(nbytes)) == EOF && eflen > 0) { - guint8 efbuf[eflen]; - _urihandle->read(efbuf, eflen); + if ( ret == EOF && eflen > 0 ) { + std::vector efbuf(eflen); + _urihandle->read(&efbuf[0], eflen); return 1; - } + } return ret; } int JarBuffer::consume_uncompressed(int nbytes) { - guint8 data[nbytes]; - if (consume(data, nbytes) == EOF) - return EOF; - - copy_to_get(data, nbytes); - compressed_left -= nbytes; - - return nbytes; + std::vector data(nbytes); + int consumed=consume(&data[0], nbytes); + if ( consumed != EOF ) { + copy_to_get(&data[0], consumed); + compressed_left -= consumed; + } + return consumed; } GByteArray *JarBuffer::inflate(guint8 *data, const int nbytes) @@ -119,11 +108,11 @@ GByteArray *JarBuffer::inflate(guint8 *data, const int nbytes) return gba; } -guint32 JarBuffer::unpack_4bytes(guint8 *data, const int offset) +guint32 JarBuffer::unpack_4bytes(guint8 *data, const int offset) { - return ((guint32)data[offset] + return ((guint32)data[offset] + (((guint32)data[offset + 1]) << 8) - + (((guint32)data[offset + 2]) << 16) + + (((guint32)data[offset + 2]) << 16) + (((guint32)data[offset + 3]) << 24)); }