Skip to content

Commit 5c09afb

Browse files
pikselNumpsy
authored andcommitted
Handle optional descriptor signature when updating
Without reverting unrelated code this time hopefully
1 parent 20e0a81 commit 5c09afb

File tree

1 file changed

+53
-58
lines changed

1 file changed

+53
-58
lines changed

src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs

Lines changed: 53 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,10 @@ public string Password
367367
}
368368
else
369369
{
370-
rawPassword_ = value;
371370
key = PkzipClassic.GenerateKeys(ZipStrings.ConvertToArray(value));
372371
}
372+
373+
rawPassword_ = value;
373374
}
374375
}
375376

@@ -533,7 +534,7 @@ public ZipFile(Stream stream, bool leaveOpen)
533534
catch
534535
{
535536
DisposeInternal(true);
536-
throw;
537+
throw;
537538
}
538539
}
539540
else
@@ -1919,11 +1920,9 @@ public void Modify(ZipEntry original, ZipEntry updated)
19191920
if ( original == null ) {
19201921
throw new ArgumentNullException("original");
19211922
}
1922-
19231923
if ( updated == null ) {
19241924
throw new ArgumentNullException("updated");
19251925
}
1926-
19271926
CheckUpdating();
19281927
contentsEdited_ = true;
19291928
updates_.Add(new ZipUpdate(original, updated));
@@ -2107,7 +2106,7 @@ private void WriteLocalEntryHeader(ZipUpdate update)
21072106
WriteLEShort(entry.Version);
21082107
WriteLEShort(entry.Flags);
21092108

2110-
WriteLEShort((byte)entry.CompressionMethod);
2109+
WriteLEShort((byte)entry.CompressionMethodForHeader);
21112110
WriteLEInt((int)entry.DosTime);
21122111

21132112
if (!entry.HasCrc)
@@ -2217,7 +2216,7 @@ private int WriteCentralDirectoryHeader(ZipEntry entry)
22172216

22182217
unchecked
22192218
{
2220-
WriteLEShort((byte)entry.CompressionMethod);
2219+
WriteLEShort((byte)entry.CompressionMethodForHeader);
22212220
WriteLEInt((int)entry.DosTime);
22222221
WriteLEInt((int)entry.Crc);
22232222
}
@@ -2775,10 +2774,6 @@ private void CopyEntryDirect(ZipFile workFile, ZipUpdate update, ref long destin
27752774
}
27762775
else
27772776
{
2778-
// TODO: Find out why this calculation comes up 4 bytes short on some entries in ODT (Office Document Text) archives.
2779-
// WinZip produces a warning on these entries:
2780-
// "caution: value of lrec.csize (compressed size) changed from ..."
2781-
27822777
// Skip entry header
27832778
destinationPosition += (sourcePosition - entryDataOffset) + NameLengthOffset;
27842779

@@ -3650,9 +3645,9 @@ private Stream CreateAndInitDecryptionStream(Stream baseStream, ZipEntry entry)
36503645
{
36513646
if (entry.Version >= ZipConstants.VERSION_AES)
36523647
{
3653-
//
3648+
// Issue #471 - accept an empty string as a password, but reject null.
36543649
OnKeysRequired(entry.Name);
3655-
if (HaveKeys == false)
3650+
if (rawPassword_ == null)
36563651
{
36573652
throw new ZipException("No password available for AES encrypted stream");
36583653
}
@@ -4041,12 +4036,12 @@ public override long Position
40414036
/// <returns>
40424037
/// The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.
40434038
/// </returns>
4044-
/// <exception cref="T:System.ArgumentException">The sum of offset and count is larger than the buffer length. </exception>
4045-
/// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
4046-
/// <exception cref="T:System.NotSupportedException">The stream does not support reading. </exception>
4047-
/// <exception cref="T:System.ArgumentNullException">buffer is null. </exception>
4048-
/// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
4049-
/// <exception cref="T:System.ArgumentOutOfRangeException">offset or count is negative. </exception>
4039+
/// <exception cref="System.ArgumentException">The sum of offset and count is larger than the buffer length. </exception>
4040+
/// <exception cref="System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
4041+
/// <exception cref="System.NotSupportedException">The stream does not support reading. </exception>
4042+
/// <exception cref="System.ArgumentNullException">buffer is null. </exception>
4043+
/// <exception cref="System.IO.IOException">An I/O error occurs. </exception>
4044+
/// <exception cref="System.ArgumentOutOfRangeException">offset or count is negative. </exception>
40504045
public override int Read(byte[] buffer, int offset, int count)
40514046
{
40524047
return 0;
@@ -4056,13 +4051,13 @@ public override int Read(byte[] buffer, int offset, int count)
40564051
/// Sets the position within the current stream.
40574052
/// </summary>
40584053
/// <param name="offset">A byte offset relative to the origin parameter.</param>
4059-
/// <param name="origin">A value of type <see cref="T:System.IO.SeekOrigin"></see> indicating the reference point used to obtain the new position.</param>
4054+
/// <param name="origin">A value of type <see cref="System.IO.SeekOrigin"></see> indicating the reference point used to obtain the new position.</param>
40604055
/// <returns>
40614056
/// The new position within the current stream.
40624057
/// </returns>
4063-
/// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
4064-
/// <exception cref="T:System.NotSupportedException">The stream does not support seeking, such as if the stream is constructed from a pipe or console output. </exception>
4065-
/// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
4058+
/// <exception cref="System.IO.IOException">An I/O error occurs. </exception>
4059+
/// <exception cref="System.NotSupportedException">The stream does not support seeking, such as if the stream is constructed from a pipe or console output. </exception>
4060+
/// <exception cref="System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
40664061
public override long Seek(long offset, SeekOrigin origin)
40674062
{
40684063
return 0;
@@ -4072,9 +4067,9 @@ public override long Seek(long offset, SeekOrigin origin)
40724067
/// Sets the length of the current stream.
40734068
/// </summary>
40744069
/// <param name="value">The desired length of the current stream in bytes.</param>
4075-
/// <exception cref="T:System.NotSupportedException">The stream does not support both writing and seeking, such as if the stream is constructed from a pipe or console output. </exception>
4076-
/// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
4077-
/// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
4070+
/// <exception cref="System.NotSupportedException">The stream does not support both writing and seeking, such as if the stream is constructed from a pipe or console output. </exception>
4071+
/// <exception cref="System.IO.IOException">An I/O error occurs. </exception>
4072+
/// <exception cref="System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
40784073
public override void SetLength(long value)
40794074
{
40804075
}
@@ -4085,12 +4080,12 @@ public override void SetLength(long value)
40854080
/// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream.</param>
40864081
/// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream.</param>
40874082
/// <param name="count">The number of bytes to be written to the current stream.</param>
4088-
/// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
4089-
/// <exception cref="T:System.NotSupportedException">The stream does not support writing. </exception>
4090-
/// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
4091-
/// <exception cref="T:System.ArgumentNullException">buffer is null. </exception>
4092-
/// <exception cref="T:System.ArgumentException">The sum of offset and count is greater than the buffer length. </exception>
4093-
/// <exception cref="T:System.ArgumentOutOfRangeException">offset or count is negative. </exception>
4083+
/// <exception cref="System.IO.IOException">An I/O error occurs. </exception>
4084+
/// <exception cref="System.NotSupportedException">The stream does not support writing. </exception>
4085+
/// <exception cref="System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
4086+
/// <exception cref="System.ArgumentNullException">buffer is null. </exception>
4087+
/// <exception cref="System.ArgumentException">The sum of offset and count is greater than the buffer length. </exception>
4088+
/// <exception cref="System.ArgumentOutOfRangeException">offset or count is negative. </exception>
40944089
public override void Write(byte[] buffer, int offset, int count)
40954090
{
40964091
baseStream_.Write(buffer, offset, count);
@@ -4170,12 +4165,12 @@ public override int ReadByte()
41704165
/// <returns>
41714166
/// The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.
41724167
/// </returns>
4173-
/// <exception cref="T:System.ArgumentException">The sum of offset and count is larger than the buffer length. </exception>
4174-
/// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
4175-
/// <exception cref="T:System.NotSupportedException">The stream does not support reading. </exception>
4176-
/// <exception cref="T:System.ArgumentNullException">buffer is null. </exception>
4177-
/// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
4178-
/// <exception cref="T:System.ArgumentOutOfRangeException">offset or count is negative. </exception>
4168+
/// <exception cref="System.ArgumentException">The sum of offset and count is larger than the buffer length. </exception>
4169+
/// <exception cref="System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
4170+
/// <exception cref="System.NotSupportedException">The stream does not support reading. </exception>
4171+
/// <exception cref="System.ArgumentNullException">buffer is null. </exception>
4172+
/// <exception cref="System.IO.IOException">An I/O error occurs. </exception>
4173+
/// <exception cref="System.ArgumentOutOfRangeException">offset or count is negative. </exception>
41794174
public override int Read(byte[] buffer, int offset, int count)
41804175
{
41814176
lock (baseStream_)
@@ -4209,12 +4204,12 @@ public override int Read(byte[] buffer, int offset, int count)
42094204
/// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream.</param>
42104205
/// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream.</param>
42114206
/// <param name="count">The number of bytes to be written to the current stream.</param>
4212-
/// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
4213-
/// <exception cref="T:System.NotSupportedException">The stream does not support writing. </exception>
4214-
/// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
4215-
/// <exception cref="T:System.ArgumentNullException">buffer is null. </exception>
4216-
/// <exception cref="T:System.ArgumentException">The sum of offset and count is greater than the buffer length. </exception>
4217-
/// <exception cref="T:System.ArgumentOutOfRangeException">offset or count is negative. </exception>
4207+
/// <exception cref="System.IO.IOException">An I/O error occurs. </exception>
4208+
/// <exception cref="System.NotSupportedException">The stream does not support writing. </exception>
4209+
/// <exception cref="System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
4210+
/// <exception cref="System.ArgumentNullException">buffer is null. </exception>
4211+
/// <exception cref="System.ArgumentException">The sum of offset and count is greater than the buffer length. </exception>
4212+
/// <exception cref="System.ArgumentOutOfRangeException">offset or count is negative. </exception>
42184213
public override void Write(byte[] buffer, int offset, int count)
42194214
{
42204215
throw new NotSupportedException();
@@ -4224,9 +4219,9 @@ public override void Write(byte[] buffer, int offset, int count)
42244219
/// When overridden in a derived class, sets the length of the current stream.
42254220
/// </summary>
42264221
/// <param name="value">The desired length of the current stream in bytes.</param>
4227-
/// <exception cref="T:System.NotSupportedException">The stream does not support both writing and seeking, such as if the stream is constructed from a pipe or console output. </exception>
4228-
/// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
4229-
/// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
4222+
/// <exception cref="System.NotSupportedException">The stream does not support both writing and seeking, such as if the stream is constructed from a pipe or console output. </exception>
4223+
/// <exception cref="System.IO.IOException">An I/O error occurs. </exception>
4224+
/// <exception cref="System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
42304225
public override void SetLength(long value)
42314226
{
42324227
throw new NotSupportedException();
@@ -4236,13 +4231,13 @@ public override void SetLength(long value)
42364231
/// When overridden in a derived class, sets the position within the current stream.
42374232
/// </summary>
42384233
/// <param name="offset">A byte offset relative to the origin parameter.</param>
4239-
/// <param name="origin">A value of type <see cref="T:System.IO.SeekOrigin"></see> indicating the reference point used to obtain the new position.</param>
4234+
/// <param name="origin">A value of type <see cref="System.IO.SeekOrigin"></see> indicating the reference point used to obtain the new position.</param>
42404235
/// <returns>
42414236
/// The new position within the current stream.
42424237
/// </returns>
4243-
/// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
4244-
/// <exception cref="T:System.NotSupportedException">The stream does not support seeking, such as if the stream is constructed from a pipe or console output. </exception>
4245-
/// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
4238+
/// <exception cref="System.IO.IOException">An I/O error occurs. </exception>
4239+
/// <exception cref="System.NotSupportedException">The stream does not support seeking, such as if the stream is constructed from a pipe or console output. </exception>
4240+
/// <exception cref="System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
42464241
public override long Seek(long offset, SeekOrigin origin)
42474242
{
42484243
long newPos = readPos_;
@@ -4267,7 +4262,7 @@ public override long Seek(long offset, SeekOrigin origin)
42674262
throw new ArgumentException("Negative position is invalid");
42684263
}
42694264

4270-
if (newPos >= end_)
4265+
if (newPos > end_)
42714266
{
42724267
throw new IOException("Cannot seek past end");
42734268
}
@@ -4278,7 +4273,7 @@ public override long Seek(long offset, SeekOrigin origin)
42784273
/// <summary>
42794274
/// Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
42804275
/// </summary>
4281-
/// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
4276+
/// <exception cref="System.IO.IOException">An I/O error occurs. </exception>
42824277
public override void Flush()
42834278
{
42844279
// Nothing to do.
@@ -4289,9 +4284,9 @@ public override void Flush()
42894284
/// </summary>
42904285
/// <value></value>
42914286
/// <returns>The current position within the stream.</returns>
4292-
/// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
4293-
/// <exception cref="T:System.NotSupportedException">The stream does not support seeking. </exception>
4294-
/// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
4287+
/// <exception cref="System.IO.IOException">An I/O error occurs. </exception>
4288+
/// <exception cref="System.NotSupportedException">The stream does not support seeking. </exception>
4289+
/// <exception cref="System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
42954290
public override long Position
42964291
{
42974292
get { return readPos_ - start_; }
@@ -4304,7 +4299,7 @@ public override long Position
43044299
throw new ArgumentException("Negative position is invalid");
43054300
}
43064301

4307-
if (newPos >= end_)
4302+
if (newPos > end_)
43084303
{
43094304
throw new InvalidOperationException("Cannot seek past end");
43104305
}
@@ -4317,8 +4312,8 @@ public override long Position
43174312
/// </summary>
43184313
/// <value></value>
43194314
/// <returns>A long value representing the length of the stream in bytes.</returns>
4320-
/// <exception cref="T:System.NotSupportedException">A class derived from Stream does not support seeking. </exception>
4321-
/// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
4315+
/// <exception cref="System.NotSupportedException">A class derived from Stream does not support seeking. </exception>
4316+
/// <exception cref="System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
43224317
public override long Length
43234318
{
43244319
get { return length_; }

0 commit comments

Comments
 (0)