Skip to content

Commit 668a4c7

Browse files
committed
Remove special treatment of NUL bytes in file names.
This brings libzip in line with unzip and 7zip and reflects usual string handling. When checking consistency, reject file names containing NUL bytes. This adresses PR #507 and issue #505.
1 parent ba55b0b commit 668a4c7

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

THANKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ Transporter <[email protected]>
173173
Vassili Courzakis <[email protected]>
174174
Vinpasso
175175
Vitaly Murashev <[email protected]>
176+
Vladislav Kachegov
176177
William Lee
177178
William Ouwehand <[email protected]>
178179
Wojciech Michalski <[email protected]>

lib/zip_dirent.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,20 @@ _zip_dirent_read(zip_dirent_t *zde, zip_source_t *src, zip_buffer_t *buffer, boo
505505
return -1;
506506
}
507507
}
508+
509+
if (check_consistency) {
510+
zip_uint8_t *p;
511+
512+
for (p = zde->filename->raw; p < zde->filename->raw + zde->filename->length; p++) {
513+
if (*p == 0) {
514+
zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_NUL_IN_FILENAME);
515+
if (!from_buffer) {
516+
_zip_buffer_free(buffer);
517+
}
518+
return -1;
519+
}
520+
}
521+
}
508522
}
509523

510524
if (ef_len) {

lib/zip_io_util.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,7 @@ _zip_read_data(zip_buffer_t *buffer, zip_source_t *src, size_t length, bool nulp
9393
}
9494

9595
if (nulp) {
96-
zip_uint8_t *o;
97-
/* replace any in-string NUL characters with spaces */
9896
r[length] = 0;
99-
for (o = r; o < r + length; o++)
100-
if (*o == '\0')
101-
*o = ' ';
10297
}
10398

10499
return r;

lib/zipint.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ extern const int _zip_err_details_count;
243243
#define ZIP_ER_DETAIL_UTF8_FILENAME_MISMATCH 23 /* E UTF-8 filename is ASCII and doesn't match filename */
244244
#define ZIP_ER_DETAIL_UTF8_COMMENT_MISMATCH 24 /* E UTF-8 comment is ASCII and doesn't match comment */
245245
#define ZIP_ER_DETAIL_COMPRESSED_DATA_TRAILING_GARBAGE 25 /* G garbage at end of compressed data */
246+
#define ZIP_ER_DETAIL_NUL_IN_FILENAME 26 /* E NUL byte in file name */
246247

247248
/* directory entry: general purpose bit flags */
248249

regress/open_incons.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ opening 'incons-local-compsize-smaller.zzip' returned error Zip archive inconsis
9595
opening 'incons-local-crc.zzip' returned error Zip archive inconsistent: entry 0: local and central headers do not match
9696
opening 'incons-local-filename-long.zzip' returned error Premature end of file
9797
opening 'incons-local-filename-missing.zzip' returned error Zip archive inconsistent: entry 0: local and central headers do not match
98-
opening 'incons-filename-nul-byte.zzip' succeeded, 1 entries
98+
opening 'incons-filename-nul-byte.zzip' returned error Zip archive inconsistent: entry 0: NUL byte in file name
9999
opening 'incons-local-filename-short.zzip' returned error Zip archive inconsistent: entry 0: extra field length is invalid
100100
opening 'incons-local-filename.zzip' returned error Zip archive inconsistent: entry 0: local and central headers do not match
101101
opening 'incons-local-magic-bad.zzip' returned error Not a zip archive
@@ -105,5 +105,5 @@ opening 'incons-streamed.zzip' returned error Zip archive inconsistent: entry 0:
105105
opening 'incons-streamed-2.zzip' returned error Zip archive inconsistent: entry 0: local header and data descriptor do not match
106106
end-of-inline-data
107107
stderr
108-
40 errors
108+
41 errors
109109
end-of-inline-data

0 commit comments

Comments
 (0)