yaffshiv icon indicating copy to clipboard operation
yaffshiv copied to clipboard

Stop parsing on invalid or trailing data

Open fabian-z opened this issue 2 years ago • 4 comments

Breaking out of the parsing loop when it is impossible to parse the read block as either data or spare entry allows yaffshiv to be used with images extracted using a detected start offset, e.g. using binwalk without a known length.

Also adjust the brute force condition, since the user requested it and FS parsing may return zero objects for incorrect settings, making brute force impossible.

fabian-z avatar Feb 06 '23 01:02 fabian-z

I also validated this change using real device NAND dumps and with generated test images, but input regarding different images would be welcome. Ping @ValdikSS as original code author :smile:

fabian-z avatar Feb 06 '23 01:02 fabian-z

Would it work for a NAND dump where not all blocks have been used just yet and are still filled with FF's?

ValdikSS avatar Feb 07 '23 06:02 ValdikSS

I could not identify a regression for this patch testing with real device dumps (reverse engineering), however the current version already fails to identify settings / find files in some cases for me. When trying to build a test environment (Linux 4.14 with nandsim and yaffs kernel module), I am hitting several different cases of invalid parsing as well, regardless if using upstream or my patch. So it is currently difficult for me to provide a reproducing test case for yaffshiv.

If 0xFF blocks are of concern, the patch can be easily adjusted to work around this issue with a code block like this:

            data_empty, spare_empty = True, True
            (obj_hdr_data, obj_hdr_spare) = self.read_block()
            for b in obj_hdr_data:
                if b != 255:
                    data_empty = False
                    break
            for b in obj_hdr_spare:
                if b != 255:
                    spare_empty = False
                    break
            if data_empty and spare_empty:
                continue

I would appreciate testing with different real-world images to ensure no regressions happen here :+1: Thanks for your efforts!

fabian-z avatar Feb 08 '23 00:02 fabian-z

Well, don't have much images, so I can't test thoroughly.

ValdikSS avatar Feb 19 '23 17:02 ValdikSS