szip: fix panic on empty files (#24335)

This commit is contained in:
JalonSolov 2025-04-29 02:07:09 -04:00 committed by GitHub
parent 57b815f96d
commit 8fc7aeca38
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View file

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