PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Infinite loop opening a PDF
http://forum.pdfsharp.com/viewtopic.php?f=3&t=739
Page 1 of 1

Author:  Thor [ Tue May 26, 2009 9:41 am ]
Post subject:  Infinite loop opening a PDF

Y use this code:
Code:
  PdfDocument doc = null;
  doc = PdfReader.Open(pathFichero, PdfDocumentOpenMode.InformationOnly);
  doc.Dispose();

With this PDF:
http://web.usal.es/~joluin/investigacio ... ichero.pdf

The file never load :(

The program PDFSharp Explorer fail too, infite loop.

I hope you can fix it.
Regards !

Author:  Thor [ Tue Dec 01, 2009 9:45 am ]
Post subject:  Re: Infinite loop opening a PDF

Finally I solved this changing in PdfSharp\Pdf\IO\Lexer.cs, in function ScanHexadecimalString() this:
Code:
      ScanNextChar();
      while (true)
      {
        MoveToNonWhiteSpace();
        if (this.currChar == '>')
        {
          ScanNextChar();
          break;
        }
        if (char.IsLetterOrDigit(this.currChar))
        {
          hex[0] = char.ToUpper(this.currChar);
          hex[1] = char.ToUpper(this.nextChar);
          int ch = int.Parse(new string(hex), NumberStyles.AllowHexSpecifier);
          this.token.Append(Convert.ToChar(ch));
          ScanNextChar();
          ScanNextChar();
        }
      }


To this:
Code:
      ScanNextChar();
      MoveToNonWhiteSpace();
      while (true)
      {
        int startPos = this.Position;
        if (this.currChar == '>')
        {
          ScanNextChar();
          break;
        }
        if (char.IsLetterOrDigit(this.currChar))
        {
          hex[0] = char.ToUpper(this.currChar);
          hex[1] = char.ToUpper(this.nextChar);
          int ch = int.Parse(new string(hex), NumberStyles.AllowHexSpecifier);
          this.token.Append(Convert.ToChar(ch));
          ScanNextChar();
          ScanNextChar();
        }
        MoveToNonWhiteSpace();
        //Si no es capaz de avanzar detener la ejecuciĆ³n del programa para evitar un bucle infinito
        //If it can't follow, stop to avoid an infinite llop
        if (this.Position == startPos)
            break;
      }


Too, I found another problem, a PDF that use the caracter 160 (Chars.NonBreakableSpace) as white space, so I added:

In:
Code:
          case Chars.NUL:
          case Chars.HT:
          case Chars.LF:
          case Chars.FF:
          case Chars.CR:
          case Chars.SP:
            ScanNextChar();
            break;


This:
Code:
          case Chars.NUL:
          case Chars.HT:
          case Chars.LF:
          case Chars.FF:
          case Chars.CR:
          case Chars.SP:
          case Chars.NonBreakableSpace:
            ScanNextChar();
            break;

I don't know if this is correct.

Regards!

Author:  Thor [ Tue Dec 01, 2009 10:28 am ]
Post subject:  Re: Infinite loop opening a PDF

PDF Reference 1.6:
Quote:
The space character is also encoded as 312 in MacRomanEncoding and as 240 in
WinAnsiEncoding. This duplicate code signifies a nonbreaking space,; it is typographi-
cally the same as space.

Numbers are in Octal notation:
240o = 160d
312o = 202d

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/