Skip to content

Commit

Permalink
Fixed IsValidRef(). Made bad checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaukala committed Dec 11, 2017
1 parent 3c346c3 commit 1614146
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
15 changes: 8 additions & 7 deletions src/PdfSharp/Pdf.IO/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,23 +1107,24 @@ private bool IsValidXref()
content += _lexer.ReadRawString(content_pos, read_length);

int ss = content.IndexOf("stream", StringComparison.Ordinal);
int eof = content.IndexOf("%%EOF", StringComparison.Ordinal);
int es = content.IndexOf("endstream", StringComparison.Ordinal);

int s = Math.Min(ss, eof);

if (s != es)
if (ss != es)
{
if (s == -1)
if (ss == -1)
return false;
else if (es == -1)
break;
else if (s < es)
else if (ss < es)
break;
else if (s > es)
else if (ss > es)
return false;
}

int eof = content.IndexOf("%%EOF", StringComparison.Ordinal);
if (eof != -1)
break;

content_pos = content_pos + read_length;
if (content_pos + read_length >= length)
{
Expand Down
12 changes: 6 additions & 6 deletions src/PdfSharp/Pdf.IO/PdfReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public static PdfDocument Open(Stream stream, string password, PdfDocumentOpenMo
public static PdfDocument Open(Stream stream, string password, PdfDocumentOpenMode openmode, PdfPasswordProvider passwordProvider)
{
PdfDocument document;
try
//try
{
Lexer lexer = new Lexer(stream);
document = new PdfDocument(lexer);
Expand Down Expand Up @@ -497,11 +497,11 @@ public static PdfDocument Open(Stream stream, string password, PdfDocumentOpenMo
document._irefTable.CheckConsistence();
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
throw;
}
// catch (Exception ex)
// {
// Debug.WriteLine(ex.Message);
// throw;
// }
return document;
}

Expand Down

0 comments on commit 1614146

Please sign in to comment.