|
3 | 3 |
|
4 | 4 | using System.Buffers.Binary;
|
5 | 5 | using System.Collections.Generic;
|
| 6 | +using System.Linq; |
6 | 7 | using System.Text;
|
7 | 8 | using System.Threading.Tasks;
|
8 | 9 | using Xunit;
|
@@ -860,6 +861,20 @@ public void ReadArchive_WithUnexpectedZip64ExtraFieldSizeUncompressedSizeIn32Bit
|
860 | 861 | Assert.Equal(6, entry.CompressedLength); // it should have used 32-bit size
|
861 | 862 | }
|
862 | 863 |
|
| 864 | + /// <summary> |
| 865 | + /// This test checks behavior of ZipArchive when the startDiskNumber in the extraField is greater than IntMax |
| 866 | + /// </summary> |
| 867 | + [Fact] |
| 868 | + public void ReadArchive_WithDiskStartNumberGreaterThanIntMax() |
| 869 | + { |
| 870 | + byte[] input = (byte[])s_zip64WithBigStartDiskNumber.Clone(); |
| 871 | + using var archive = new ZipArchive(new MemoryStream(input)); |
| 872 | + |
| 873 | + var exception = Record.Exception(() => archive.Entries.First()); |
| 874 | + |
| 875 | + Assert.Null(exception); |
| 876 | + } |
| 877 | + |
863 | 878 | private static readonly byte[] s_slightlyIncorrectZip64 =
|
864 | 879 | {
|
865 | 880 | // ===== Local file header signature 0x04034b50
|
@@ -1000,5 +1015,154 @@ public void ReadArchive_WithUnexpectedZip64ExtraFieldSizeUncompressedSizeIn32Bit
|
1000 | 1015 | // comment length
|
1001 | 1016 | 0x00, 0x00
|
1002 | 1017 | };
|
| 1018 | + |
| 1019 | + private static readonly byte[] s_zip64WithBigStartDiskNumber = |
| 1020 | + { |
| 1021 | + // ===== Local file header signature 0x04034b50 |
| 1022 | + 0x50, 0x4b, 0x03, 0x04, |
| 1023 | + // version to extract 4.5 |
| 1024 | + 0x2d, 0x00, |
| 1025 | + // general purpose flags |
| 1026 | + 0x00, 0x08, // 0000_1000 'for enhanced deflating' |
| 1027 | + // Deflate |
| 1028 | + 0x08, 0x00, |
| 1029 | + // Last mod file time |
| 1030 | + 0x17, 0x9b, |
| 1031 | + // Last mod date |
| 1032 | + 0x6d, 0x52, |
| 1033 | + // CRC32 |
| 1034 | + 0x0c, 0x7e, 0x7f, 0xd8, |
| 1035 | + // compressed size |
| 1036 | + 0xff, 0xff, 0xff, 0xff, |
| 1037 | + // UNcompressed size |
| 1038 | + 0xff, 0xff, 0xff, 0xff, |
| 1039 | + // file name length |
| 1040 | + |
| 1041 | + 0x08, 0x00, |
| 1042 | + // extra field length |
| 1043 | + 0x20, 0x00, |
| 1044 | + // filename |
| 1045 | + 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x74, 0x78, 0x74, |
| 1046 | + // -----Zip64 extra field tag |
| 1047 | + 0x01, 0x00, |
| 1048 | + // size of extra field block |
| 1049 | + 0x20, 0x00, |
| 1050 | + // 8 byte Zip64 UNcompressed size, index 42 |
| 1051 | + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1052 | + // 8 byte Zip64 compressed size, index 50 |
| 1053 | + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1054 | + // 8 byte Relative Header Offset |
| 1055 | + 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1056 | + // Disk Start Number |
| 1057 | + 0xff, 0xff, 0xff, 0xfe, |
| 1058 | + // ----- NTFS extra field tag |
| 1059 | + 0x0a, 0x00, |
| 1060 | + // size of extra field block |
| 1061 | + 0x20, 0x00, |
| 1062 | + // reserved |
| 1063 | + 0x00, 0x00, 0x00, 0x00, |
| 1064 | + // tag #1 |
| 1065 | + 0x01, 0x00, |
| 1066 | + // size of tag #1 |
| 1067 | + 0x18, 0x00, |
| 1068 | + // Mtime, CTime, Atime |
| 1069 | + 0xa8, 0xb1, 0xf6, 0x61, 0x25, 0x18, 0xd7, 0x01, |
| 1070 | + 0xa8, 0xb1, 0xf6, 0x61, 0x25, 0x18, 0xd7, 0x01, |
| 1071 | + 0xa8, 0xb1, 0xf6, 0x61, 0x25, 0x18, 0xd7, 0x01, |
| 1072 | + // ------------- |
| 1073 | + // Data! |
| 1074 | + 0x2b, 0x49, 0x2d, 0x2e, 0x01, 0x00, |
| 1075 | + // -------- Central directory signature 0x02014b50 |
| 1076 | + 0x50, 0x4b, 0x01, 0x02, |
| 1077 | + // version made by 4.5 |
| 1078 | + 0x2d, 0x00, |
| 1079 | + // version to extract 4.5 |
| 1080 | + 0x2d, 0x00, |
| 1081 | + // general purpose flags |
| 1082 | + 0x00, 0x08, |
| 1083 | + // Deflate |
| 1084 | + 0x08, 0x00, |
| 1085 | + // Last mod file time |
| 1086 | + 0x17, 0x9b, |
| 1087 | + // Last mod date |
| 1088 | + 0x6d, 0x52, |
| 1089 | + // CRC32 |
| 1090 | + 0x0c, 0x7e, 0x7f, 0xd8, |
| 1091 | + // 4 byte compressed size, index 120 (-1 indicates refer to Zip64 extra field) |
| 1092 | + 0xff, 0xff, 0xff, 0xff, |
| 1093 | + // 4 byte UNcompressed size, index 124 (-1 indicates refer to Zip64 extra field) |
| 1094 | + 0xff, 0xff, 0xff, 0xff, |
| 1095 | + // file name length |
| 1096 | + 0x08, 0x00, |
| 1097 | + // extra field length |
| 1098 | + 0x44, 0x00, |
| 1099 | + // file comment length |
| 1100 | + 0x00, 0x00, |
| 1101 | + // disk number start (-1 indicates refer to Zip64 extra field) |
| 1102 | + 0xff, 0xff, |
| 1103 | + // internal file attributes |
| 1104 | + 0x00, 0x00, |
| 1105 | + // external file attributes |
| 1106 | + 0x00, 0x00, 0x00, 0x00, |
| 1107 | + // relative offset of local header (-1 indicates refer to Zip64 extra field) |
| 1108 | + 0x00, 0x00, 0x00, 0x00, |
| 1109 | + // file name |
| 1110 | + 0x66, 0x69, 0x6c, 0x65, 0x2e, 0x74, 0x78, 0x74, |
| 1111 | + // extra field, content similar to before |
| 1112 | + 0x01, 0x00, |
| 1113 | + 0x1c, 0x00, |
| 1114 | + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1115 | + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1116 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1117 | + // Disk start number |
| 1118 | + 0xff, 0xff, 0xff, 0xfe, |
| 1119 | + 0x0a, 0x00, |
| 1120 | + 0x20, 0x00, |
| 1121 | + 0x00, 0x00, 0x00, 0x00, |
| 1122 | + 0x01, 0x00, 0x18, 0x00, |
| 1123 | + 0xa8, 0xb1, 0xf6, 0x61, 0x25, 0x18, 0xd7, 0x01, |
| 1124 | + 0xa8, 0xb1, 0xf6, 0x61, 0x25, 0x18, 0xd7, 0x01, |
| 1125 | + 0xa8, 0xb1, 0xf6, 0x61, 0x25, 0x18, 0xd7, 0x01, |
| 1126 | + // == 'end of zip64 central directory record' signature 0x06064b50 |
| 1127 | + 0x50, 0x4b, 0x06, 0x06, |
| 1128 | + // size |
| 1129 | + 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1130 | + // version made by, version needed |
| 1131 | + 0x2d, 0x00, 0x2d, 0x00, |
| 1132 | + // disk number, disk number with CD |
| 1133 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1134 | + // total number of CD records |
| 1135 | + 0x01, 0x00, 0x00, 0x00, |
| 1136 | + // size of CD |
| 1137 | + 0x00, 0x00, 0x00, 0x00, |
| 1138 | + // offset of start of CD wrt starting disk |
| 1139 | + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1140 | + // zip64 extensible data sector |
| 1141 | + 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1142 | + // offset of start cd |
| 1143 | + 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1144 | + // == 'zip64 end of CD locator' signature 0x07064b50 |
| 1145 | + 0x50, 0x4b, 0x06, 0x07, |
| 1146 | + // number of disk with zip64 CD |
| 1147 | + 0x00, 0x00, 0x00, 0x00, |
| 1148 | + // relative offset of zip64 ECD |
| 1149 | + 0xea, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1150 | + // total number of disks |
| 1151 | + 0x01, 0x00, 0x00, 0x00, |
| 1152 | + // == 'end of CD' signature 0x06054b50 |
| 1153 | + 0x50, 0x4b, 0x05, 0x06, |
| 1154 | + // disk number, disk number with CD (-1 indicates refer to Zip64 extra field) |
| 1155 | + 0x00, 0x00, |
| 1156 | + 0x00, 0x00, |
| 1157 | + // total number of entries in CD on this disk, and overall (-1 indicates refer to Zip64 extra fields) |
| 1158 | + 0xff, 0xff, |
| 1159 | + 0xff, 0xff, |
| 1160 | + // size of CD (-1 indicates refer to Zip64 extra field) |
| 1161 | + 0x7a, 0x00, 0x00, 0x00, |
| 1162 | + // offset of start of CD wrt start disk (-1 indicates refer to Zip64 extra field) |
| 1163 | + 0x70, 0x00, 0x00, 0x00, |
| 1164 | + // comment length |
| 1165 | + 0x00, 0x00 |
| 1166 | + }; |
1003 | 1167 | }
|
1004 | 1168 | }
|
0 commit comments