fix bug in encryption handler. couple of code style tweaks

This commit is contained in:
Eliot Jones
2021-05-09 12:31:51 -04:00
parent a85bcb4ec1
commit 421dd74840
4 changed files with 148 additions and 160 deletions

View File

@@ -466,6 +466,8 @@
}
private static StringToken GetStringTokenFromDecryptedData(byte[] data)
{
if (data.Length >= 2)
{
if (data[0] == 0xFE && data[1] == 0xFF)
{
@@ -480,6 +482,7 @@
return new StringToken(str, StringToken.Encoding.Utf16);
}
}
return new StringToken(OtherEncodings.BytesAsLatin1String(data), StringToken.Encoding.Iso88591);
}

View File

@@ -2,8 +2,8 @@
{
using System;
using System.IO;
using UglyToad.PdfPig.IO;
using UglyToad.PdfPig.Util;
using IO;
using Util;
/// <summary>
/// CCITT Modified Huffman RLE, Group 3 (T4) and Group 4 (T6) fax compression.
@@ -30,7 +30,7 @@
private int changesReferenceRowCount;
private int changesCurrentRowCount;
private int lastChangingElement = 0;
private int lastChangingElement;
private int buffer = -1;
private int bufferPos = -1;
@@ -78,7 +78,7 @@
{
DecodeRow();
}
catch (IOException)
catch (InvalidOperationException)
{
if (decodedLength != 0)
{
@@ -344,7 +344,7 @@
if (index != columns)
{
throw new IOException("Sum of run-lengths does not equal scan line width: " + index + " > " + columns);
throw new InvalidOperationException("Sum of run-lengths does not equal scan line width: " + index + " > " + columns);
}
decodedLength = (index + 7) / 8;
@@ -363,7 +363,7 @@
if (node == null)
{
throw new IOException("Unknown code in Huffman RLE stream");
throw new InvalidOperationException("Unknown code in Huffman RLE stream");
}
if (node.IsLeaf)
@@ -398,7 +398,7 @@
if (buffer == -1)
{
throw new IOException("Unexpected end of Huffman RLE stream");
throw new InvalidOperationException("Unexpected end of Huffman RLE stream");
}
bufferPos = 0;
@@ -528,7 +528,7 @@
}
else if (next.IsLeaf)
{
throw new IOException("node is leaf, no other following");
throw new InvalidOperationException("node is leaf, no other following");
}
current = next;
@@ -565,7 +565,7 @@
}
else if (next.IsLeaf)
{
throw new IOException("node is leaf, no other following");
throw new InvalidOperationException("node is leaf, no other following");
}
current = next;

View File

@@ -36,39 +36,24 @@
Stream.Write(buffer, offset, count);
}
public override bool CanRead
{
get { return Stream.CanRead; }
}
public override bool CanRead => Stream.CanRead;
public override bool CanSeek
{
get { return Stream.CanSeek; }
}
public override bool CanSeek => Stream.CanSeek;
public override bool CanWrite
{
get { return Stream.CanWrite; }
}
public override bool CanWrite => Stream.CanWrite;
public override long Length
{
get { return Stream.Length; }
}
public override long Length => Stream.Length;
public override long Position
{
get { return Stream.Position; }
set { Stream.Position = value; }
get => Stream.Position;
set => Stream.Position = value;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
// dispose stream
using (Stream)
{
}
Stream?.Dispose();
}
}
}