system/corennnnn
Révision | 287c71ca84533da008e9cc240224910a9d05139e (tree) |
---|---|
l'heure | 2009-06-17 09:36:04 |
Auteur | Doug Zongker <dougz@andr...> |
Commiter | Doug Zongker |
fix decompression bug in fastboot
fastboot passes the *uncompressed* length of the file as the length of
the input to the inflate() call, which happens to work unless the
compressed data is actually larger than the uncompressed data (which
it can be for very small files). Fix this to pass the correct
compressed length down to the inflate call.
@@ -13,7 +13,7 @@ enum { | ||
13 | 13 | // central directory entries |
14 | 14 | ENTRY_SIGNATURE = 0x02014b50, |
15 | 15 | ENTRY_LEN = 46, // CentralDirEnt len, excl. var fields |
16 | - | |
16 | + | |
17 | 17 | // local file header |
18 | 18 | LFH_SIZE = 30, |
19 | 19 | }; |
@@ -73,8 +73,6 @@ read_central_directory_entry(Zipfile* file, Zipentry* entry, | ||
73 | 73 | unsigned short lastModFileTime; |
74 | 74 | unsigned short lastModFileDate; |
75 | 75 | unsigned long crc32; |
76 | - unsigned long compressedSize; | |
77 | - unsigned long uncompressedSize; | |
78 | 76 | unsigned short extraFieldLength; |
79 | 77 | unsigned short fileCommentLength; |
80 | 78 | unsigned short diskNumberStart; |
@@ -85,7 +83,7 @@ read_central_directory_entry(Zipfile* file, Zipentry* entry, | ||
85 | 83 | const unsigned char* fileComment; |
86 | 84 | unsigned int dataOffset; |
87 | 85 | unsigned short lfhExtraFieldSize; |
88 | - | |
86 | + | |
89 | 87 | |
90 | 88 | p = *buf; |
91 | 89 |
@@ -106,7 +104,7 @@ read_central_directory_entry(Zipfile* file, Zipentry* entry, | ||
106 | 104 | lastModFileTime = read_le_short(&p[0x0c]); |
107 | 105 | lastModFileDate = read_le_short(&p[0x0e]); |
108 | 106 | crc32 = read_le_int(&p[0x10]); |
109 | - compressedSize = read_le_int(&p[0x14]); | |
107 | + entry->compressedSize = read_le_int(&p[0x14]); | |
110 | 108 | entry->uncompressedSize = read_le_int(&p[0x18]); |
111 | 109 | entry->fileNameLength = read_le_short(&p[0x1c]); |
112 | 110 | extraFieldLength = read_le_short(&p[0x1e]); |
@@ -141,14 +139,14 @@ read_central_directory_entry(Zipfile* file, Zipentry* entry, | ||
141 | 139 | fileComment = NULL; |
142 | 140 | } |
143 | 141 | p += fileCommentLength; |
144 | - | |
142 | + | |
145 | 143 | *buf = p; |
146 | 144 | |
147 | 145 | // the size of the extraField in the central dir is how much data there is, |
148 | 146 | // but the one in the local file header also contains some padding. |
149 | 147 | p = file->buf + localHeaderRelOffset; |
150 | 148 | extraFieldLength = read_le_short(&p[0x1c]); |
151 | - | |
149 | + | |
152 | 150 | dataOffset = localHeaderRelOffset + LFH_SIZE |
153 | 151 | + entry->fileNameLength + extraFieldLength; |
154 | 152 | entry->data = file->buf + dataOffset; |
@@ -243,7 +241,7 @@ read_central_dir(Zipfile *file) | ||
243 | 241 | free(entry); |
244 | 242 | goto bail; |
245 | 243 | } |
246 | - | |
244 | + | |
247 | 245 | // add it to our list |
248 | 246 | entry->next = file->entries; |
249 | 247 | file->entries = entry; |
@@ -253,4 +251,3 @@ read_central_dir(Zipfile *file) | ||
253 | 251 | bail: |
254 | 252 | return -1; |
255 | 253 | } |
256 | - |
@@ -82,13 +82,13 @@ uninflate(unsigned char* out, int unlen, const unsigned char* in, int clen) | ||
82 | 82 | unsigned long crc; |
83 | 83 | int err = 0; |
84 | 84 | int zerr; |
85 | - | |
85 | + | |
86 | 86 | memset(&zstream, 0, sizeof(zstream)); |
87 | 87 | zstream.zalloc = Z_NULL; |
88 | 88 | zstream.zfree = Z_NULL; |
89 | 89 | zstream.opaque = Z_NULL; |
90 | 90 | zstream.next_in = (void*)in; |
91 | - zstream.avail_in = unlen; | |
91 | + zstream.avail_in = clen; | |
92 | 92 | zstream.next_out = (Bytef*) out; |
93 | 93 | zstream.avail_out = unlen; |
94 | 94 | zstream.data_type = Z_UNKNOWN; |
@@ -99,7 +99,7 @@ uninflate(unsigned char* out, int unlen, const unsigned char* in, int clen) | ||
99 | 99 | if (zerr != Z_OK) { |
100 | 100 | return -1; |
101 | 101 | } |
102 | - | |
102 | + | |
103 | 103 | // uncompress the data |
104 | 104 | zerr = inflate(&zstream, Z_FINISH); |
105 | 105 | if (zerr != Z_STREAM_END) { |
@@ -107,7 +107,7 @@ uninflate(unsigned char* out, int unlen, const unsigned char* in, int clen) | ||
107 | 107 | zstream.total_out); |
108 | 108 | err = -1; |
109 | 109 | } |
110 | - | |
110 | + | |
111 | 111 | inflateEnd(&zstream); |
112 | 112 | return err; |
113 | 113 | } |