Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
Adding/correcting comments in test, and slightly reducing the diff in ZipArchiveEntry.
  • Loading branch information
edwardneal committed Jan 31, 2025
1 parent 8999361 commit 63a1fac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ internal ZipArchiveEntry(ZipArchive archive, ZipCentralDirectoryFileHeader cd)
_archive = archive;

_originallyInArchive = true;
Changes = ZipArchive.ChangeState.Unchanged;

_diskNumberStart = cd.DiskNumberStart;
_versionMadeByPlatform = (ZipVersionMadeByPlatform)cd.VersionMadeByCompatibility;
_versionMadeBySpecification = (ZipVersionNeededValues)cd.VersionMadeBySpecification;
_versionToExtract = (ZipVersionNeededValues)cd.VersionNeededToExtract;
_generalPurposeBitFlag = (BitFlagValues)cd.GeneralPurposeBitFlag;
_isEncrypted = (_generalPurposeBitFlag & BitFlagValues.IsEncrypted) != 0;
// Setting CompressionMethod can change the _versionToExtract variable, which can change the value of Changes
CompressionMethod = (CompressionMethodValues)cd.CompressionMethod;
_lastModified = new DateTimeOffset(ZipHelper.DosTimeToDateTime(cd.LastModified));
_compressedSize = cd.CompressedSize;
_uncompressedSize = cd.UncompressedSize;
Expand All @@ -86,10 +89,6 @@ internal ZipArchiveEntry(ZipArchive archive, ZipCentralDirectoryFileHeader cd)

_fileComment = cd.FileComment;

Changes = ZipArchive.ChangeState.Unchanged;

// Setting CompressionMethod can change the _versionToExtract variable, which can change the value of Changes
CompressionMethod = (CompressionMethodValues)cd.CompressionMethod;
_compressionLevel = MapCompressionLevel(_generalPurposeBitFlag, CompressionMethod);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ public static void ZipArchive_InvalidVersionToExtract()
Assert.Equal(0x00, originalLocalVersionToExtract);
Assert.Equal(0x00, originalCentralDirectoryVersionToExtract);

// Write the example data to the stream. We expect to be able to read it (and the entry contents) successfully.
updatedStream.Write(s_inconsistentVersionToExtract);
updatedStream.Seek(0, SeekOrigin.Begin);

Expand Down Expand Up @@ -983,7 +984,7 @@ public static void ZipArchive_InvalidVersionToExtract()
0x46, 0xd7, 0x6c, 0x45,
// compressed size
0x0c, 0x00, 0x00, 0x00,
// UNcompressed size
// uncompressed size
0x0a, 0x00, 0x00, 0x00,
// file name length
0x09, 0x00,
Expand Down Expand Up @@ -1012,7 +1013,7 @@ public static void ZipArchive_InvalidVersionToExtract()
0x46, 0xd7, 0x6c, 0x45,
// compressed size
0x0c, 0x00, 0x00, 0x00,
// UNcompressed size
// uncompressed size
0x0a, 0x00, 0x00, 0x00,
// file name length
0x09, 0x00,
Expand Down Expand Up @@ -1064,7 +1065,7 @@ public static void ZipArchive_InvalidVersionToExtract()
0x0c, 0x7e, 0x7f, 0xd8,
// compressed size
0xff, 0xff, 0xff, 0xff,
// UNcompressed size
// uncompressed size
0xff, 0xff, 0xff, 0xff,
// file name length
0x08, 0x00,
Expand Down Expand Up @@ -1115,7 +1116,7 @@ public static void ZipArchive_InvalidVersionToExtract()
0x0c, 0x7e, 0x7f, 0xd8,
// 4 byte compressed size, index 120 (-1 indicates refer to Zip64 extra field)
0xff, 0xff, 0xff, 0xff,
// 4 byte UNcompressed size, index 124 (-1 indicates refer to Zip64 extra field)
// 4 byte uncompressed size, index 124 (-1 indicates refer to Zip64 extra field)
0xff, 0xff, 0xff, 0xff,
// file name length
0x08, 0x00,
Expand Down Expand Up @@ -1205,7 +1206,7 @@ public static void ZipArchive_InvalidVersionToExtract()
0x0c, 0x7e, 0x7f, 0xd8,
// compressed size
0xff, 0xff, 0xff, 0xff,
// UNcompressed size
// uncompressed size
0xff, 0xff, 0xff, 0xff,
// file name length

Expand All @@ -1218,7 +1219,7 @@ public static void ZipArchive_InvalidVersionToExtract()
0x01, 0x00,
// size of extra field block
0x20, 0x00,
// 8 byte Zip64 UNcompressed size, index 42
// 8 byte Zip64 uncompressed size, index 42
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 8 byte Zip64 compressed size, index 50
0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down Expand Up @@ -1261,7 +1262,7 @@ public static void ZipArchive_InvalidVersionToExtract()
0x0c, 0x7e, 0x7f, 0xd8,
// 4 byte compressed size, index 120 (-1 indicates refer to Zip64 extra field)
0xff, 0xff, 0xff, 0xff,
// 4 byte UNcompressed size, index 124 (-1 indicates refer to Zip64 extra field)
// 4 byte uncompressed size, index 124 (-1 indicates refer to Zip64 extra field)
0xff, 0xff, 0xff, 0xff,
// file name length
0x08, 0x00,
Expand Down

0 comments on commit 63a1fac

Please sign in to comment.