Skip to content
Tcl Source Code View Ticket
Login

View Ticket

signed integer overflow in ZipReadInt()

Closed / Fixed0061c7a476f141128775d7982dc807f0ecf00d6aCreated 5 years agoUpdated 5 years ago
Descriptionwiki2022-04-16 16:40:27
UBSan (-fsanitize=shift-base) error:
tcl/generic/tclZipfs.c:470:55: runtime error: left shift of 252 by 24 places cannot be represented in type 'int'

Avoid by casting to unsigned int before shifting:

--- generic/tclZipfs.c.orig
+++ generic/tclZipfs.c
@@ -467,7 +467,8 @@ ZipReadInt(
        Tcl_Panic("out of bounds read(4): start=%p, end=%p, ptr=%p",
                bufferStart, bufferEnd, ptr);
     }
-    return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
+    return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) |
+           ((unsigned int)ptr[3] << 24);
 }
 
 static inline unsigned short
Referenced by1
chrstphrchvz Ticket [0061c7a476]: 3 changes [History diff]2022-04-16 16:41:49
jan.nijtmanswiki2022-04-18 16:56:32

Fixed [here]

Thanks for the report and the patch!

Log in (anonymous is fine) to add a comment.