njcrawford / EmbroideryReader

Open source .PES file viewer
GNU General Public License v2.0
39 stars 20 forks source link

Crash when opening certain files #19

Closed njcrawford closed 5 years ago

njcrawford commented 7 years ago

I'm not sure what's causing this yet, but I've now had several automated reports of a crash when opening a file. The most recent one is below.

Program: embroideryReader, Version=2.2.3.0, Culture=neutral, PublicKeyToken=null Program location: C:\Program Files (x86)\NJCrawford Software\Embroidery Reader\embroideryReader.exe OS: Windows 10 Home release 1703 (6.3 build 15063) (x64) OS Culture: en-US Framework: 4.0.30319.42000 (x64)

Error: System.ArgumentOutOfRangeException (Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index) at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at PesFile.PesFile.OpenFile(String filename) at embroideryReader.frmMain.openFile(String filename) at embroideryReader.frmMain.Form1_Load(Object sender, EventArgs e) at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at embroideryReader.frmMain.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

njcrawford commented 7 years ago

Another one, received on May 4:

Program: embroideryReader, Version=2.2.3.0, Culture=neutral, PublicKeyToken=null Program location: C:\Program Files (x86)\NJCrawford Software\Embroidery Reader\embroideryReader.exe OS: Windows 8.1 Connected (6.3 build 9600) (x64) OS Culture: en-US Framework: 4.0.30319.36366 (x64)

Error: System.ArgumentOutOfRangeException (Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index) at System.Collections.Generic.List`1.get_Item(Int32 index) at PesFile.PesFile.OpenFile(String filename) at embroideryReader.frmMain.openFile(String filename) at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at embroideryReader.frmMain.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

njcrawford commented 7 years ago

Another, received 2016-12-17:

Program: embroideryReader, Version=2.2.3.0, Culture=neutral, PublicKeyToken=null Program location: C:\Program Files (x86)\NJCrawford Software\Embroidery Reader\embroideryReader.exe OS: Windows 10 Pro release 1607 (6.3 build 14393) (x64) OS Culture: en-AU Framework: 4.0.30319.42000 (x64)

Error: System.ArgumentOutOfRangeException (Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index) at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at PesFile.PesFile.OpenFile(String filename) at embroideryReader.frmMain.openFile(String filename) at embroideryReader.frmMain.Form1_Load(Object sender, EventArgs e) at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at embroideryReader.frmMain.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

njcrawford commented 7 years ago

Possibly related report from version 2.1.0, received 2016-05-08:

Program: embroideryReader, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null Program location: C:\Program Files (x86)\NJCrawford Software\Embroidery Reader\embroideryReader.exe OS: Microsoft Windows NT 6.1.7601 Service Pack 1 OS Culture: en-US Framework: 4.0.30319.34209

Error: System.ArgumentOutOfRangeException (Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index) at System.Collections.Generic.List`1.get_Item(Int32 index) at PesFile.PesFile.OpenFile(String filename) at embroideryReader.frmMain.openFile(String filename) at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at embroideryReader.frmMain.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

njcrawford commented 7 years ago

Emailed the most recent reporter to see if they could remember the file they were trying to open, and see if they're willing to share it with me to fix this issue.

njcrawford commented 7 years ago

Received another report on 2017-06-21, and emailed the reporter to see if they would be willing to share the file that caused it:

Program: embroideryReader, Version=2.2.3.0, Culture=neutral, PublicKeyToken=null Program location: C:\Program Files (x86)\NJCrawford Software\Embroidery Reader\embroideryReader.exe OS: Windows 10 Home release 1607 (6.3 build 14393) (x64) OS Culture: en-US Framework: 4.0.30319.42000 (x64)

Error: System.ArgumentOutOfRangeException (Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index) at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at PesFile.PesFile.OpenFile(String filename) at embroideryReader.frmMain.openFile(String filename) at embroideryReader.frmMain.openToolStripMenuItem_Click(Object sender, EventArgs e) at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e) at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e) at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ToolStrip.WndProc(Message& m) at System.Windows.Forms.ToolStripDropD (Report clipped)

njcrawford commented 7 years ago

Reporter of the crash yesterday replied that they were opening a folder in Embroidery Reader. I haven't been able to reproduce it yet. They also said it was a duplicate file and they had deleted it, and hadn't seen the issue again since.

It might be a good idea to put more error checking in the open function to try to track this down.

njcrawford commented 6 years ago

Another error report received today:

Program: embroideryReader, Version=2.2.3.0, Culture=neutral, PublicKeyToken=null Program location: C:\Program Files (x86)\NJCrawford Software\Embroidery Reader\embroideryReader.exe OS: Windows 10 Pro release 1703 (6.3 build 15063) (x64) OS Culture: en-US Framework: 4.0.30319.42000 (x64)

Error: System.ArgumentOutOfRangeException (Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index) at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at PesFile.PesFile.OpenFile(String filename) at embroideryReader.frmMain.openFile(String filename) at embroideryReader.frmMain.Form1_Load(Object sender, EventArgs e) at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at embroideryReader.frmMain.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

njcrawford commented 6 years ago

Yet another received this weekend with the same stack trace:

Program: embroideryReader, Version=2.2.3.0, Culture=neutral, PublicKeyToken=null Program location: C:\Program Files (x86)\NJCrawford Software\Embroidery Reader\embroideryReader.exe OS: Windows 7 Professional Service Pack 1 (6.1 build 7601) (x64) OS Culture: en-US Framework: 4.0.30319.42000 (x64)

Error: System.ArgumentOutOfRangeException (Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index) at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at PesFile.PesFile.OpenFile(String filename) at embroideryReader.frmMain.openFile(String filename) at embroideryReader.frmMain.Form1_Load(Object sender, EventArgs e) at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at embroideryReader.frmMain.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

njcrawford commented 6 years ago

After a quick review of the OpenFile() function, there were 2 array accesses that didn't check the bounds of the array. If a file was corrupted in a specific way, it could have contained more blocks than it claimed and the counter would increment beyond the end of the array.

The change included in afd3e809077dbd82ee5e70933579dfe15df66526 checks the index and throws a more informative exception if it would be beyond the end of the array.

njcrawford commented 5 years ago

Recently I've received 4 files from 2 users that were causing this crash. This has allowed me to come up with a fix for the crash, or at least a workaround in code. It appears that the byte I was reading to mean number of blocks has some other meaning... perhaps number of thread changes? Without having an embroidery machine myself, it's hard to tell what it's actually doing.