Skip to content

Return errors for corrupt sector chains instead of log.Fatal or reading forever - #6

Open
AntoniKwok wants to merge 1 commit into
extrame:masterfrom
AntoniKwok:fix/corrupt-sector-chains
Open

AntoniKwok wants to merge 1 commit into
extrame:masterfrom
AntoniKwok:fix/corrupt-sector-chains

Conversation

@AntoniKwok

Copy link
Copy Markdown

Damaged OLE2 containers currently crash or hang the host program:

  • StreamReader.Read calls log.Fatal when a sector id is past the allocation table, terminating the process.
  • A cyclic sector chain (or a DIFAT chain that loops) makes Read return data forever / readMSAT spin, so callers that read until EOF never finish.
  • Seek indexes sat[...] without a bounds check.

Changes:

  • New ErrCorruptChain; Read/Seek follow chains through a helper that fails after len(sat)+1 steps or on an out-of-table sector id (counted per call, so repeated seeks to the start are fine).
  • Read stops at the stream's declared size (when known) and tracks the offset.
  • readMSAT rejects a revisited DIFAT sector.

Tests cover a looping chain, an out-of-table chain and the size limit. Valid files read exactly as before (verified by parsing a 275 KB real-world workbook and comparing every cell).

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