PHDuy / excellibrary

Automatically exported from code.google.com/p/excellibrary
0 stars 0 forks source link

Crash at SubRecord.cs with exception {"Unable to read beyond the end of the stream."} #51

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Just loaded a regular XLS document (Office 2007) on the winform test project
2.
3.

What is the expected output? What do you see instead?

Hex View and Text View worked fine, but the Excell view constantly crashed
at Subrecord.cs / ReadBase(Stream stream) > record.Size =
reader.ReadUInt16() line, because the binary stream had reached the end.

What version of the product are you using? On what operating system?

The latest build on XP Pro, SP3, Visual Studio 2008 Pro

Please provide any additional information below.

I have modified the subroutine as such as a remedy.

public new static SubRecord ReadBase(Stream stream)
{
BinaryReader reader = new BinaryReader(stream);
// [SokSa]Icy: The reader consumes with each read, sometimes causing a
crash at record.Size = reader.ReadUInt16() line
// as the stream may have been consumed entirely by that time.
// Peek one char to verify that there is something left in the binary
stream before attempting read   
if (reader.PeekChar() == -1) return null;
SubRecord record = new SubRecord();
record.Type = reader.PeekChar() == -1 ? Convert.ToUInt16(0) :
reader.ReadUInt16();
record.Size = reader.PeekChar() == -1 ? Convert.ToUInt16(0) :
reader.ReadUInt16();
record.Data = reader.ReadBytes(record.Size);
return record;
}

Original issue reported on code.google.com by ihsan...@gmail.com on 26 Nov 2009 at 2:03

GoogleCodeExporter commented 8 years ago
Although this code works, it will allow corrupted file.

Original comment by China.LiuJunFeng on 2 Feb 2010 at 3:14