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

Bug in BPB validation #101

Open
dbalsom opened this issue Nov 19, 2024 · 2 comments
Open

Bug in BPB validation #101

dbalsom opened this issue Nov 19, 2024 · 2 comments

Comments

@dbalsom
Copy link

dbalsom commented Nov 19, 2024

        if (self.total_sectors_16 == 0) == (self.total_sectors_32 == 0) {
            error!("Invalid BPB (total_sectors_16 or total_sectors_32 should be non-zero)");
            return Err(Error::CorruptedFileSystem);
        }

I believe this should be

        if (self.total_sectors_16 == 0) && (self.total_sectors_32 == 0) {
            error!("Invalid BPB (total_sectors_16 or total_sectors_32 should be non-zero)");
            return Err(Error::CorruptedFileSystem);
        }

Otherwise it will cause a failure if both total_sectors_16 and total_sectors_32 are nonzero, which is the case on many DOS disk images

@rafalh
Copy link
Owner

rafalh commented Nov 19, 2024

FAT specification says:

BPB_TotSec16:

This field can be 0; if it is 0, then BPB_TotSec32
must be non-zero. For FAT32 volumes, this field
must be 0.
For FAT12 and FAT16 volumes, this field contains
the sector count, and BPB_TotSec32 is 0 if the
total sector count “fits” (is less than 0x10000).

BPB_TotSec32:

This field can be 0; if it is 0, then BPB_TotSec16
must be non-zero. For FAT12/FAT16 volumes, this
field contains the sector count if BPB_TotSec16 is
0 (count is greater than or equal to 0x10000).
For FAT32 volumes, this field must be non-zero.

so for FAT32 BPB_TotSec16 should always be zero and for FAT12 and FAT16 it should only be non-zero if sector count is < 0x10000.

Well, docs are not fully specific if BPB_TotSec32 must be zero if sector count is < 0x10000, so maybe it should be changed. I wonder if all modern tools agree on those fields.

Do I understand it right that you tried to read some old image and encouraged this problem? What image it was?

@dbalsom
Copy link
Author

dbalsom commented Nov 19, 2024

disk.zip

here is an example. there are very many dos games that fall into this pattern

it opens with WinImage and DiskImageTool (https://github.com/Digitoxin1/DiskImageTool)

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