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

Fix the mini-stream size in the root property #731

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

ebourg
Copy link
Member

@ebourg ebourg commented Nov 21, 2024

This is a follow up to #182, which didn't cover all possibles cases of gaps in the allocation table of the mini stream.

This PR contains a unit test generating a file with the following layout:

  • Mini FAT Sector 1 is unallocated
  • Mini FAT Sector 2 has 8 unallocated mini sectors at the beginning
  • Mini FAT Sector 3 has 4 unallocated mini sectors in the middle
  • Mini FAT Sector 4 is unallocated
  • Mini FAT Sector 5 has 32 unallocated mini sectors at the end
  • Mini FAT Sector 6 has 64 unallocated sectors at the beginning and 16 unallocated mini sectors at the end
  • Mini FAT Sector 7 is unallocated
  • Mini FAT Sector 8 is unallocated

With this layout POI 5.3 computes a mini stream size of 29696 bytes, that is the sum of the "occupied" bytes (as per BATBlock.getOccupiedSize()) for each sector : (0 + 128 + 128 + 0 + (128-32) + (128-16) + 0 + 0) x 64.

After signing the file with signtool:

  • The first 2 mini sectors of the first mini FAT sector have been allocated (for the MsiDigitalSignatureEx entry)
  • The empty mini FAT sectors 4, 7 and 8 were not removed
  • The size field of the root entry is 48128 bytes, that's (5 x 128 + (128 - 16)) x 64

So the right method to compute the size is to find the absolute index of the last allocated mini sector, add one and multiply by 64.

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.

1 participant