pvginkel / PdfiumViewer

PDF viewer based on Google's PDFium.
Apache License 2.0
967 stars 418 forks source link

BUG: Load(string path) does not close the stream using e.g. a corrupted PDF #136

Open derguterat opened 6 years ago

derguterat commented 6 years ago

Opening a corrupted PDF (eg. a file with a size of 0) using Load(string path) or Load(string path, string password) locks the file till closing the application because the filestream is not disposed. Load(IWin32Window owner, string path) does not shows this behavior.

I have solved this problem as follows:

public class PdfDocument : IPdfDocument
{
[...]
        // new static function
        private static FileStream OpenRead(string path)
        {
            FileStream fs = null; 
            using (fs = File.OpenRead(path))
            {
            }

            return fs;
        }
[...]

instead in using File.OpenRead(path) I use the new static function OpenRead.