LogicAndTrick / sledge

An open source alternative to Valve's Hammer Editor for the Goldsource engine. (No longer in development)
https://logicandtrick.github.io/sledge/
BSD 3-Clause "New" or "Revised" License
302 stars 81 forks source link

GenericStructure.ParseStructure enters infinite loop on unexpected EOF #215

Open quantumdude836 opened 9 years ago

quantumdude836 commented 9 years ago

Sledge.Providers/GenericStructure.cs:635 - if reader doesn't have any more data, it returns null. String.IsNullOrWhiteSpace(null) is true, so the loop will never end. You could add something like:

if (line == null)
    throw new WhateverException("EOF trying to parse generic structure");

For reference, materials/models/gibs/combine_helicopter_gibs/combine_helicopter02.vmt from Half-Life 2: Episode Two has an extra 's' in it.

LogicAndTrick commented 6 years ago

This bug still exists in the new release, the new file location is SerialisedObjectFormatter.cs:122

This example code replicates the bug:

var invalid = "Invalid\n{\ns";

var ms = new MemoryStream(Encoding.ASCII.GetBytes(invalid));
var fmt = new SerialisedObjectFormatter();
fmt.Deserialize(ms).Dump();

The invalid VMT has since been patched in HL2 EP2.