mdsteele / rust-cfb

Rust library for reading/writing Compound File Binary (structured storage) files
MIT License
46 stars 20 forks source link

Malformed FAT (FAT sector xxx is not marked as such in the FAT) #30

Closed inzanez closed 2 years ago

inzanez commented 2 years ago

Hi

I am reading Microsoft MSG files and from time to time I get the message above. Reading these MSG files with MSG readers does work, so I wonder how or why that would be an issue?

A sample would be: https://www.file.io/r5AB/download/BHSIDV1A4qJU

Best regards...

mdsteele commented 2 years ago

Thanks for the report and example file!

FAT sectors are supposed to be represented in the FAT itself by the FATSECT = 0xFFFFFFFD constant (see section 2.3 of the MS-CFB spec). However, for some reason the FAT in this file is representing itself as a regular sector chain (with each FAT sector's entry in the FAT pointing to the next, terminated by an ENDOFCHAIN). Yet another entry in the annals of "CFB files in the wild not comporting to the spec." (-: Anyway, the cfb crate is complaining about the spec violation in this file, but I guess some other MSG readers are more lenient.

Since we already know (from parsing the DIFAT) which sectors are in the FAT and should therefore be marked with FATSECT, probably the solution is to do what I've done for other bugs like this: ignore the incorrect value when parsing, and just pretend it was what it's supposed to be. I'll take a look.

inzanez commented 2 years ago

@mdsteele Many thanks for the quick answer! That's quite interesting. Yes, I can imagine that there are quite a lot of files out there that do not comply with the specs,...pretty much the same as for other files like RTF :-)

ikrivosheev commented 2 years ago

@mdsteele maybe we can report it to microsoft? To fix the RFC?