Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions PdfSharpCore/Pdf.IO/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,15 +562,19 @@ public Symbol ScanHexadecimalString()
ScanNextChar(true);
break;
}
if (char.IsLetterOrDigit(_currChar))
if (IsHexChar(_currChar))
{
hex[0] = char.ToUpper(_currChar);
hex[1] = char.ToUpper(_nextChar);
int ch = int.Parse(new string(hex), NumberStyles.AllowHexSpecifier);
hex[0] = _currChar;
hex[1] = IsHexChar(_nextChar) ? _nextChar : ' ';
int ch = int.Parse(new string(hex), NumberStyles.HexNumber);
_token.Append(Convert.ToChar(ch));
ScanNextChar(true);
ScanNextChar(true);
if (_currChar != '>')
ScanNextChar(true);
}
else
// prevent endless loop in case _currChar is neither '>' nor a hex-char nor whitespace
ScanNextChar(true);
}
string chars = _token.ToString();
int count = chars.Length;
Expand All @@ -585,6 +589,13 @@ public Symbol ScanHexadecimalString()
return _symbol = Symbol.HexString;
}

internal static bool IsHexChar(char c)
{
return char.IsDigit(c) ||
(c >= 'A' && c <= 'F') ||
(c >= 'a' && c <= 'f');
}

/// <summary>
/// Move current position one character further in PDF stream.
/// </summary>
Expand Down