mirror of
https://github.com/UglyToad/PdfPig.git
synced 2026-03-10 00:23:29 +08:00
fix bug in encryption handler. couple of code style tweaks
This commit is contained in:
@@ -467,18 +467,21 @@
|
|||||||
|
|
||||||
private static StringToken GetStringTokenFromDecryptedData(byte[] data)
|
private static StringToken GetStringTokenFromDecryptedData(byte[] data)
|
||||||
{
|
{
|
||||||
if (data[0] == 0xFE && data[1] == 0xFF)
|
if (data.Length >= 2)
|
||||||
{
|
{
|
||||||
var str = Encoding.BigEndianUnicode.GetString(data).Substring(1);
|
if (data[0] == 0xFE && data[1] == 0xFF)
|
||||||
|
{
|
||||||
|
var str = Encoding.BigEndianUnicode.GetString(data).Substring(1);
|
||||||
|
|
||||||
return new StringToken(str, StringToken.Encoding.Utf16BE);
|
return new StringToken(str, StringToken.Encoding.Utf16BE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data[0] == 0xFF && data[1] == 0xFE)
|
if (data[0] == 0xFF && data[1] == 0xFE)
|
||||||
{
|
{
|
||||||
var str = Encoding.Unicode.GetString(data).Substring(1);
|
var str = Encoding.Unicode.GetString(data).Substring(1);
|
||||||
|
|
||||||
return new StringToken(str, StringToken.Encoding.Utf16);
|
return new StringToken(str, StringToken.Encoding.Utf16);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new StringToken(OtherEncodings.BytesAsLatin1String(data), StringToken.Encoding.Iso88591);
|
return new StringToken(OtherEncodings.BytesAsLatin1String(data), StringToken.Encoding.Iso88591);
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using UglyToad.PdfPig.IO;
|
using IO;
|
||||||
using UglyToad.PdfPig.Util;
|
using Util;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// CCITT Modified Huffman RLE, Group 3 (T4) and Group 4 (T6) fax compression.
|
/// CCITT Modified Huffman RLE, Group 3 (T4) and Group 4 (T6) fax compression.
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
private int changesReferenceRowCount;
|
private int changesReferenceRowCount;
|
||||||
private int changesCurrentRowCount;
|
private int changesCurrentRowCount;
|
||||||
|
|
||||||
private int lastChangingElement = 0;
|
private int lastChangingElement;
|
||||||
|
|
||||||
private int buffer = -1;
|
private int buffer = -1;
|
||||||
private int bufferPos = -1;
|
private int bufferPos = -1;
|
||||||
@@ -78,7 +78,7 @@
|
|||||||
{
|
{
|
||||||
DecodeRow();
|
DecodeRow();
|
||||||
}
|
}
|
||||||
catch (IOException)
|
catch (InvalidOperationException)
|
||||||
{
|
{
|
||||||
if (decodedLength != 0)
|
if (decodedLength != 0)
|
||||||
{
|
{
|
||||||
@@ -344,7 +344,7 @@
|
|||||||
|
|
||||||
if (index != columns)
|
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;
|
decodedLength = (index + 7) / 8;
|
||||||
@@ -363,7 +363,7 @@
|
|||||||
|
|
||||||
if (node == null)
|
if (node == null)
|
||||||
{
|
{
|
||||||
throw new IOException("Unknown code in Huffman RLE stream");
|
throw new InvalidOperationException("Unknown code in Huffman RLE stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.IsLeaf)
|
if (node.IsLeaf)
|
||||||
@@ -398,7 +398,7 @@
|
|||||||
|
|
||||||
if (buffer == -1)
|
if (buffer == -1)
|
||||||
{
|
{
|
||||||
throw new IOException("Unexpected end of Huffman RLE stream");
|
throw new InvalidOperationException("Unexpected end of Huffman RLE stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
bufferPos = 0;
|
bufferPos = 0;
|
||||||
@@ -528,7 +528,7 @@
|
|||||||
}
|
}
|
||||||
else if (next.IsLeaf)
|
else if (next.IsLeaf)
|
||||||
{
|
{
|
||||||
throw new IOException("node is leaf, no other following");
|
throw new InvalidOperationException("node is leaf, no other following");
|
||||||
}
|
}
|
||||||
|
|
||||||
current = next;
|
current = next;
|
||||||
@@ -565,7 +565,7 @@
|
|||||||
}
|
}
|
||||||
else if (next.IsLeaf)
|
else if (next.IsLeaf)
|
||||||
{
|
{
|
||||||
throw new IOException("node is leaf, no other following");
|
throw new InvalidOperationException("node is leaf, no other following");
|
||||||
}
|
}
|
||||||
|
|
||||||
current = next;
|
current = next;
|
||||||
|
|||||||
@@ -36,39 +36,24 @@
|
|||||||
Stream.Write(buffer, offset, count);
|
Stream.Write(buffer, offset, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanRead
|
public override bool CanRead => Stream.CanRead;
|
||||||
{
|
|
||||||
get { return Stream.CanRead; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool CanSeek
|
public override bool CanSeek => Stream.CanSeek;
|
||||||
{
|
|
||||||
get { return Stream.CanSeek; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool CanWrite
|
public override bool CanWrite => Stream.CanWrite;
|
||||||
{
|
|
||||||
get { return Stream.CanWrite; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public override long Length
|
public override long Length => Stream.Length;
|
||||||
{
|
|
||||||
get { return Stream.Length; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public override long Position
|
public override long Position
|
||||||
{
|
{
|
||||||
get { return Stream.Position; }
|
get => Stream.Position;
|
||||||
set { Stream.Position = value; }
|
set => Stream.Position = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
// dispose stream
|
Stream?.Dispose();
|
||||||
using (Stream)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user