@@ -1070,3 +1070,62 @@ func TestIssue12449(t *testing.T) {
1070
1070
t .Errorf ("Error reading the archive: %v" , err )
1071
1071
}
1072
1072
}
1073
+
1074
+ func TestCVE202133196 (t * testing.T ) {
1075
+ // Archive that indicates it has 1 << 128 -1 files,
1076
+ // this would previously cause a panic due to attempting
1077
+ // to allocate a slice with 1 << 128 -1 elements.
1078
+ data := []byte {
1079
+ 0x50 , 0x4b , 0x03 , 0x04 , 0x14 , 0x00 , 0x08 , 0x08 ,
1080
+ 0x08 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
1081
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
1082
+ 0x00 , 0x00 , 0x03 , 0x00 , 0x00 , 0x00 , 0x01 , 0x02 ,
1083
+ 0x03 , 0x62 , 0x61 , 0x65 , 0x03 , 0x04 , 0x00 , 0x00 ,
1084
+ 0xff , 0xff , 0x50 , 0x4b , 0x07 , 0x08 , 0xbe , 0x20 ,
1085
+ 0x5c , 0x6c , 0x09 , 0x00 , 0x00 , 0x00 , 0x03 , 0x00 ,
1086
+ 0x00 , 0x00 , 0x50 , 0x4b , 0x01 , 0x02 , 0x14 , 0x00 ,
1087
+ 0x14 , 0x00 , 0x08 , 0x08 , 0x08 , 0x00 , 0x00 , 0x00 ,
1088
+ 0x00 , 0x00 , 0xbe , 0x20 , 0x5c , 0x6c , 0x09 , 0x00 ,
1089
+ 0x00 , 0x00 , 0x03 , 0x00 , 0x00 , 0x00 , 0x03 , 0x00 ,
1090
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
1091
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
1092
+ 0x01 , 0x02 , 0x03 , 0x50 , 0x4b , 0x06 , 0x06 , 0x2c ,
1093
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x2d ,
1094
+ 0x00 , 0x2d , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
1095
+ 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 ,
1096
+ 0x00 , 0x00 , 0x00 , 0xff , 0xff , 0xff , 0xff , 0xff ,
1097
+ 0xff , 0xff , 0xff , 0x31 , 0x00 , 0x00 , 0x00 , 0x00 ,
1098
+ 0x00 , 0x00 , 0x00 , 0x3a , 0x00 , 0x00 , 0x00 , 0x00 ,
1099
+ 0x00 , 0x00 , 0x00 , 0x50 , 0x4b , 0x06 , 0x07 , 0x00 ,
1100
+ 0x00 , 0x00 , 0x00 , 0x6b , 0x00 , 0x00 , 0x00 , 0x00 ,
1101
+ 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x50 ,
1102
+ 0x4b , 0x05 , 0x06 , 0x00 , 0x00 , 0x00 , 0x00 , 0xff ,
1103
+ 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ,
1104
+ 0xff , 0xff , 0xff , 0x00 , 0x00 ,
1105
+ }
1106
+ _ , err := NewReader (bytes .NewReader (data ), int64 (len (data )))
1107
+ if err != ErrFormat {
1108
+ t .Fatalf ("unexpected error, got: %v, want: %v" , err , ErrFormat )
1109
+ }
1110
+
1111
+ // Also check that an archive containing a handful of empty
1112
+ // files doesn't cause an issue
1113
+ b := bytes .NewBuffer (nil )
1114
+ w := NewWriter (b )
1115
+ for i := 0 ; i < 5 ; i ++ {
1116
+ _ , err := w .Create ("" )
1117
+ if err != nil {
1118
+ t .Fatalf ("Writer.Create failed: %s" , err )
1119
+ }
1120
+ }
1121
+ if err := w .Close (); err != nil {
1122
+ t .Fatalf ("Writer.Close failed: %s" , err )
1123
+ }
1124
+ r , err := NewReader (bytes .NewReader (b .Bytes ()), int64 (b .Len ()))
1125
+ if err != nil {
1126
+ t .Fatalf ("NewReader failed: %s" , err )
1127
+ }
1128
+ if len (r .File ) != 5 {
1129
+ t .Errorf ("Archive has unexpected number of files, got %d, want 5" , len (r .File ))
1130
+ }
1131
+ }
0 commit comments