onekey-sec/unblob

Implement a size overflow check in a base handler class.

Closed this issue · 4 comments

All format handlers calculate the expected size of a chunk. We should implement a generic check that verifies if the calculated end_offset points after the actual end of a file.

Something along those lines:

def overflow(file: io.BufferedReader, end_offset: int):
    file.seek(0, os.SEEK_END)
    size = file.tell()
    return end_offset > size

This is an easy win in terms of heuristics, to get rid of invalid and corrupted headers.

Depends on #21

We should emit an error log about this.

I fully agree.

Done in #47