rickomax / psxprev

PSXPREV - Playstation (PSX) Files Previewer/Extractor
BSD 2-Clause "Simplified" License
200 stars 10 forks source link

StreamBounds wrapper class to track the farthest area read in a file #98

Open trigger-segfault opened 1 year ago

trigger-segfault commented 1 year ago

When a parser succeeds, the scanner relies on the current position of the reader stream to use as the start of the next offset. A lot of times, a file may read sections and then skip back to the beginning of the file, and even end scanning there. because of this, more processing time is wasted scanning areas that were already confirmed to be a part of another file.

The idea for a solution is to either make a Stream or BinaryReader wrapper that tracks the highest position the stream is at (mainly by logging the position during Seek). This way, the highest offset can be used.

There are some issues to consider with this though, and it may even be better to make this an option, rather than forced on. For example, if scanning a large file and you get a very high pointer offset that points to garbage data, you'll end up excluding a ton of the file if the parser has a false positive and succeeds.

trigger-segfault commented 1 year ago

A class FileOffsetStream has been implemented by PR #117, however this isn't used yet due to the issues described above.