When I invoke SwfReader.ReadSwf() on my program, sometimes it will encounter exception bellow:
System.IO.EndOfStreamException was unhandled
Message="Unable to read beyond the end of the stream."
Source="mscorlib"
StackTrace:
at System.IO.__Error.EndOfFile()
at System.IO.BinaryReader.ReadByte()
at SwfDotNet.IO.Utils.BufferedBinaryReader.ReadByte() xxx\SwfDotNet.IO\Utils\BufferedBinaryReader.cs:line 108
at SwfDotNet.IO.Tags.SoundStreamBlockTag.ReadData(Byte version, BufferedBinaryReader binaryReader) in xxx\SwfProccesser\SwfDotNet.IO\Tags\SoundStreamBlockTag.cs:line 122
at SwfDotNet.IO.SwfReader.ReadTag(Byte version, BufferedBinaryReader binaryReader, BaseTagCollection tagList) in xxx\SwfProccesser\SwfDotNet.IO\SwfReader.cs:line 346
at SwfDotNet.IO.SwfReader.ReadSwf() in xxx\SwfProccesser\SwfDotNet.IO\SwfReader.cs:line 207
When I rewrite the method as follow the problem will be resolved.
public Swf ReadSwf()
{
// compressed swf?
if (br.PeekChar()=='C')
Inflate();
SwfHeader header = new SwfHeader();
header.ReadData(br);
this.version = header.Version;
tagList = new BaseTagCollection();
bool readEndTag = false; //necessary for the 1 more byte bug
//
// Here has a bug, for fix the bug, I just rashly minus the length 500.
// ---- by Jeff Zhang(ncwzhj@qq.com)
while (br.BaseStream.Position < br.BaseStream.Length && !readEndTag)
{
BaseTag b = SwfReader.ReadTag(this.version, this.br, this.tagList);
if (b != null)
{
if (b is EndTag)
readEndTag = true;
tagList.Add(b);
}
};
br.Close();
return new Swf(header, tagList);
}
at line 203