FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fixes Zlib compression issues. by GitHubProUser67 · Pull Request #648 · bcgit/bc-csharp · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cs  (3) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 1 addition & 3 deletions crypto/src/util/zlib/ZInputStream.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static ZStream GetDefaultZStream(bool nowrap)
return z;
}

private const int BufferSize = 4096;
private const int BufferSize = 512;

protected ZStream z;
protected int flushLevel = JZlib.Z_NO_FLUSH;
Expand Down Expand Up @@ -186,8 +186,6 @@ public override int Read(byte[] buffer, int offset, int count)
if (nomoreinput && err == JZlib.Z_BUF_ERROR)
return 0;
if (err != JZlib.Z_OK && err != JZlib.Z_STREAM_END)
// TODO
//throw new ZStreamException((compress ? "de" : "in") + "flating: " + z.msg);
throw new IOException((compress ? "de" : "in") + "flating: " + z.msg);
if ((nomoreinput || err == JZlib.Z_STREAM_END) && z.avail_out == count)
return 0;
Expand Down
16 changes: 7 additions & 9 deletions crypto/src/util/zlib/ZOutputStream.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,18 @@ public virtual void End()

public virtual void Finish()
{
int err;
do
{
z.next_out = buf;
z.next_out_index = 0;
z.avail_out = buf.Length;

int err = compress
err = compress
? z.deflate(JZlib.Z_FINISH)
: z.inflate(JZlib.Z_FINISH);

if (err != JZlib.Z_STREAM_END && err != JZlib.Z_OK)
// TODO
//throw new ZStreamException((compress?"de":"in")+"flating: "+z.msg);
throw new IOException((compress ? "de" : "in") + "flating: " + z.msg);

int count = buf.Length - z.avail_out;
Expand All @@ -190,7 +189,7 @@ public virtual void Finish()
output.Write(buf, 0, count);
}
}
while (z.avail_in > 0 || z.avail_out == 0);
while ((z.avail_in > 0 || z.avail_out == 0) && err == JZlib.Z_OK);

Flush();
}
Expand Down Expand Up @@ -227,24 +226,23 @@ public override void Write(byte[] buffer, int offset, int count)
z.next_in_index = offset;
z.avail_in = count;

int err;
do
{
z.next_out = buf;
z.next_out_index = 0;
z.avail_out = buf.Length;

int err = compress
err = compress
? z.deflate(flushLevel)
: z.inflate(flushLevel);

if (err != JZlib.Z_OK)
// TODO
//throw new ZStreamException((compress ? "de" : "in") + "flating: " + z.msg);
if (err != JZlib.Z_OK && err != JZlib.Z_STREAM_END)
throw new IOException((compress ? "de" : "in") + "flating: " + z.msg);

output.Write(buf, 0, buf.Length - z.avail_out);
}
while (z.avail_in > 0 || z.avail_out == 0);
while ((z.avail_in > 0 || z.avail_out == 0) && err == JZlib.Z_OK);
}

public override void WriteByte(byte value)
Expand Down
22 changes: 15 additions & 7 deletions crypto/src/util/zlib/ZStream.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,21 @@ internal void flush_pending(){
if(len>avail_out) len=avail_out;
if(len==0) return;

if(dstate.pending_buf.Length<=dstate.pending_out ||
next_out.Length<=next_out_index ||
dstate.pending_buf.Length<(dstate.pending_out+len) ||
next_out.Length<(next_out_index+len)){
// System.out.println(dstate.pending_buf.length+", "+dstate.pending_out+
// ", "+next_out.length+", "+next_out_index+", "+len);
// System.out.println("avail_out="+avail_out);
if (this.dstate.pending_buf.Length <= this.dstate.pending_out || this.next_out.Length <= this.next_out_index || this.dstate.pending_buf.Length < this.dstate.pending_out + len || this.next_out.Length < this.next_out_index + len)
{
Console.Out.WriteLine(string.Concat(new object[]
{
this.dstate.pending_buf.Length,
", ",
this.dstate.pending_out,
", ",
this.next_out.Length,
", ",
this.next_out_index,
", ",
len
}));
Console.Out.WriteLine("avail_out=" + this.avail_out);
}

System.Array.Copy(dstate.pending_buf, dstate.pending_out,
Expand Down

Back | FazBrowse Home | New Git URL