Skip to content

Commit 8fc7aec

Browse files
authored
szip: fix panic on empty files (#24335)
1 parent 57b815f commit 8fc7aec

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

vlib/compress/szip/szip.c.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub fn (mut zentry Zip) crc32() u32 {
183183

184184
// write_entry compresses an input buffer for the current zip entry.
185185
pub fn (mut zentry Zip) write_entry(data []u8) ! {
186-
if int(data[0] & 0xff) == -1 {
186+
if data.len > 0 && int(data[0] & 0xff) == -1 {
187187
return error('szip: cannot write entry')
188188
}
189189
res := C.zip_entry_write(zentry, data.data, data.len)

vlib/compress/szip/szip_test.v

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,11 @@ fn test_zip_folder_omit_empty_directories() {
170170
assert (os.read_file(fpath5)!) == '5'
171171
assert (os.read_file(fpath6)!) == '6'
172172
}
173+
174+
fn test_zip_folder_empty_file() {
175+
cleanup()
176+
os.mkdir_all(test_path)!
177+
os.write_file('${test_path}/test.txt', '')! // Empty file
178+
szip.zip_folder(test_path, test_dir_zip)!
179+
assert os.exists(test_dir_zip)
180+
}

0 commit comments

Comments
 (0)