Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script processing fails on files smaller than 8 bytes ... #145

Closed
nagblock opened this issue Jul 24, 2016 · 1 comment
Closed

Script processing fails on files smaller than 8 bytes ... #145

nagblock opened this issue Jul 24, 2016 · 1 comment

Comments

@nagblock
Copy link

... by throwing an unexpected exception. This is due to the code calling Processor.IsDumpStream which assumes that the input stream is large enough for reading a 64 bit magic value.

My suggested fix:
Change MoonSharp.Interpreter.Execution.VM.Processor.IsDumpStreamfrom

internal static bool IsDumpStream(Stream stream)
{
    using (BinaryReader br = new BinaryReader(stream, Encoding.UTF8))
    {
        ulong magic = br.ReadUInt64();
        stream.Seek(-8, SeekOrigin.Current);
        return magic == DUMP_CHUNK_MAGIC;
    }
}

to

internal static bool IsDumpStream(Stream stream)
{
    if (stream.Length >= 8)
    {
        using (BinaryReader br = new BinaryReader(stream, Encoding.UTF8))
        {
            ulong magic = br.ReadUInt64();
            stream.Seek(-8, SeekOrigin.Current);
            return magic == DUMP_CHUNK_MAGIC;
        }
    }
    return false;
}
@xanathar
Copy link
Member

xanathar commented Oct 3, 2016

Thanks for the fix. Added to coming 1.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants