ebourg commented on PR #182: URL: https://github.com/apache/poi/pull/182#issuecomment-2489837342
I'm late to the party, I stumbled on this PR as I was debugging a MSI file with an invalid signature generated by Jsign (using POI 5.3.0). This file has 6 mini FAT sectors, the first 4 sectors are full with all mini sectors allocated, and the last two sectors have the following layout: ``` Sector #88115 : Mini FAT #5 Mini FAT entries: [...] 120 : 633 121 : 634 122 : 635 123 : 636 124 : -2 (End of chain) 125 : -2 (End of chain) 126 : -1 (Free sector) 127 : -1 (Free sector) Sector #173743 : Mini FAT #6 Mini FAT entries: 0 : -1 (Free sector) 1 : -1 (Free sector) 2 : -1 (Free sector) 3 : -2 (End of chain) 4-127 : -1 (Free sector) ``` For this file POI computes 4 x 128 + 126 + 4 = 642 mini sectors, for a size of 41088 bytes. However signtool expects 644 mini sectors (41216 bytes) in order to validate the signature. It looks like the occupied size has only to be computed for the last mini FAT sector, and the other sectors are counted as fully allocated. In this case it gives 5 x 128 + 4 = 644. I don't know how the size is computed if the last mini FAT sector consists only of unallocated mini sectors, for example: ``` Sector #88115 : Mini FAT #5 Mini FAT entries: [...] 120 : 633 121 : 634 122 : 635 123 : 636 124 : -2 (End of chain) 125 : -2 (End of chain) 126 : -1 (Free sector) 127 : -1 (Free sector) Sector #173743 : Mini FAT #6 Mini FAT entries: 0-127 : -1 (Free sector) ``` In this case signtool could either: * trim the last sector, and there would be 4 x 128 + 126 = 638 mini sectors * keep the last sector but ignoring it, so 638 mini sectors * keep the last sector and count as guessed above, so 5 x 128 + 0 = 640 mini sectors -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org For additional commands, e-mail: dev-h...@poi.apache.org