diff --git a/Data/MidiData.cs b/Data/MidiData.cs
index 32abdd1..bafdeb2 100644
--- a/Data/MidiData.cs
+++ b/Data/MidiData.cs
@@ -100,8 +100,14 @@ protected static int ReadVLQ(byte[] bytes, int index)
/* A variable-length quantity is in big-endian order, and only the lowest seven bits of each byte are part of the
* quantity. The Most Significant Bit (MSB) is set in all bytes except the last. It can be up to four bytes long.
*/
+
for (int i = 0, n = 0; i < 4; ++i)
{
+ if ((index + i) >= bytes.Length)
+ {
+ throw new ApplicationException(Properties.Resources.InvalidVLQ + string.Format(" offset {0}", index + i));
+ }
+
/* As appropriate, initialize the result (or shift it seven bits
* to the left) and add to it the lowest seven bits of this byte.
*/
diff --git a/Data/Sets/MidiFile.cs b/Data/Sets/MidiFile.cs
index c0f470a..ed2891f 100644
--- a/Data/Sets/MidiFile.cs
+++ b/Data/Sets/MidiFile.cs
@@ -25,6 +25,8 @@ namespace JeffBourdier
/// Represents a standard MIDI file (essentially, a collection of MidiChunk objects).
public class MidiFile : MidiSet
{
+
+
/****************
* Constructors *
****************/
@@ -36,7 +38,14 @@ public class MidiFile : MidiSet
public MidiFile(string filePath) : base(new List())
{
byte[] bytes = File.ReadAllBytes(filePath);
- this.Replace(bytes);
+ try
+ {
+ this.Replace(bytes);
+ }
+ catch (Exception ex)
+ {
+ CreationException = ex;
+ }
}
/// Initializes a new instance of the MidiFile class with a header (MThd) chunk.
@@ -55,6 +64,9 @@ public MidiFile(MidiHeaderChunk header) : base(new List(1))
#region Public Methods
+ public Exception CreationException { get; set; }
+
+
/// Gets the chunk at the specified index.
/// The zero-based index of the chunk to get.
/// The chunk at the specified index.
diff --git a/MIDIopsyWindow.cs b/MIDIopsyWindow.cs
index c69e733..6d65971 100644
--- a/MIDIopsyWindow.cs
+++ b/MIDIopsyWindow.cs
@@ -276,6 +276,11 @@ protected override bool OpenFile(string filePath)
return false;
}
+ if (!(this.MidiFile.CreationException==null)){
+ MessageBox.Show(String.Format("warning: {0}", this.MidiFile.CreationException.Message), Meta.Name, MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+
+
/* Load the file object into the UI. */
this.LoadFile();
return true;