Skip to content

Commit 242102f

Browse files
jedisct1andrewrk
authored andcommitted
std/zip.zig: perform backslash-to-forward-slash before isBadFilename()
Previously, when extracting a ZIP file, isBadFilename(), which is designed to reject ../ patterns to prevent directory traversal, was called before normalizing backslashes to forward slashes. This allowed path traversal sequences like ..\\..\\..\\etc\\passwd which pass validation but are then converted to ../../../etc/passwd for file extraction.
1 parent 6de2310 commit 242102f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/std/zip.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,16 +536,16 @@ pub const Iterator = struct {
536536
@as(u64, local_header.extra_len);
537537
};
538538

539-
if (isBadFilename(filename))
540-
return error.ZipBadFilename;
541-
542539
if (options.allow_backslashes) {
543540
std.mem.replaceScalar(u8, filename, '\\', '/');
544541
} else {
545542
if (std.mem.indexOfScalar(u8, filename, '\\')) |_|
546543
return error.ZipFilenameHasBackslash;
547544
}
548545

546+
if (isBadFilename(filename))
547+
return error.ZipBadFilename;
548+
549549
// All entries that end in '/' are directories
550550
if (filename[filename.len - 1] == '/') {
551551
if (self.uncompressed_size != 0)

0 commit comments

Comments
 (0)