Skip to content

Conversation

sftse
Copy link
Contributor

@sftse sftse commented Jul 7, 2025

I ran into errors of the form

'Malformed FAT (FAT has 14976 entries, but DIFAT lists 14976 as a DIFAT sector)'

and tracked it down to a FREE_SECTOR at the end of the file. When the FREE_SECTOR are stripped from the end of the FAT, and the DIFAT points to that sector, then the call to fn validate will not have a chance to try and fix the .cfb.
With this fix the files that had the error now succeed.

I may try and come up with a synthetic version of those files, but I'm making this PR without them for now. I also added some of the code I wrote to debug this.

}

#[derive(Clone, PartialEq, Eq)]
pub(crate) enum Ty {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does Ty stand for?

Copy link
Contributor Author

@sftse sftse Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short for Type. Muscle memory kicked in because type is a reserved keyword, commonly abbreviated to ty, but doesn't have the same issue when uppercased as Type. Can change.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks

sftse added 5 commits July 17, 2025 11:58
Some cfbs manage to mislabel their sectors so badly that their DIFAT chain
mentions sectors that are labeled FREE in the FAT. When the trimming of the FAT
strips those sectors from the end of the FAT, these will error with

'Malformed FAT (FAT has 14976 entries, but DIFAT lists 14976 as a DIFAT sector)'

By ensuring the FAT is always padded with FREE_SECTOR to the end of the file,
fn validate() has a chance to correct the mislabeled sectors.
@sftse
Copy link
Contributor Author

sftse commented Jul 17, 2025

Rebased on master

@sftse sftse requested a review from mdsteele July 17, 2025 10:04
@mdsteele mdsteele merged commit 3e6bd0a into mdsteele:master Jul 19, 2025
4 checks passed
@sftse sftse deleted the pad-with-free branch July 20, 2025 12:05
@sftse sftse mentioned this pull request Jul 22, 2025
mdsteele added a commit that referenced this pull request Jul 24, 2025
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

Successfully merging this pull request may close these issues.

2 participants