Accept root-relative internal relationship targets (fixes silent shared-string loss on Mono) - #88
Merged
rabanti-github merged 1 commit intoAug 25, 2026
Conversation
An internal relationship whose Target begins with '/' is a root-relative path, which OPC permits. ParseRelationship rejected it because Uri.IsAbsoluteUri disagrees across runtimes for that shape: .NET parses "/xl/sharedStrings.xml" as a RELATIVE Uri, Mono parses it as ABSOLUTE. On Mono the relationship is therefore discarded as "an internal relationship target cannot be an absolute URI". Because sharedStrings is looked up as an optional relationship, the reader then skips the shared strings part silently and every string cell is returned holding its raw shared-string INDEX instead of its text -- no exception, correct cell count, wrong values. Microsoft Excel writes exactly this shape: in a workbook produced by Excel 16.0, 26 of 27 relationships are plain relative and the sharedStrings one is "/xl/sharedStrings.xml", so any Excel-authored workbook can hit it. Reproduced on Mono 6.12 (Unity's editor runtime); .NET 8/10 are unaffected. Test for a real scheme rather than trusting IsAbsoluteUri, and rebuild the target as relative so PackUriHelper.ResolvePartUri agrees on both runtimes. A genuinely absolute target (http://...) is still rejected.
Owner
|
Thanks for the bugfix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey, I've updated to the new release today, and stumbled upon a smal hiccup with linux Mono build.
Summary
On Mono, 3.2.0 silently returns every string cell as its raw shared-string index instead of its text. No exception is thrown, the worksheet count is right, the cell count is right and numeric cells are right — only the strings are wrong. 3.1.0 is unaffected. .NET is unaffected on both Windows and Linux.
This matters for Unity, whose editor runs Mono: my item-balance importer reads an Excel-authored workbook at build time and got
0,64,133,132whereid,value,domain,descriptionbelong. I only noticed because my own code hard-fails on a missing header — a more permissive consumer would have written the indices straight into its output.Root cause
DiscoveryReader.ParseRelationshiprejects an internal relationship whose target is an absolute URI, and decides that withUri.IsAbsoluteUri:Uri.IsAbsoluteUridisagrees between runtimes for a root-relative path:TargetsharedStrings.xmlfalsefalse/xl/sharedStrings.xmlfalsetruehttp://example.com/x.xmltruetrueA leading-slash target is a root-relative path, which OPC permits for an internal relationship — it is not an absolute URI in the sense this check intends. On Mono the relationship is therefore discarded into
Issues, and sinceXlsxReaderlooks up shared strings as an optional relationship:…the part is skipped with no diagnostic, and every
t="s"cell keeps its index.Why this is not exotic
Microsoft Excel writes exactly this shape. In my workbook (Excel 16.0,
AppVersion 16.0300), 26 of 27 relationships are plain relative and the sharedStrings one is/xl/sharedStrings.xml. So any Excel-authored workbook can trip it, and only on Mono.The fix
Test for a real scheme rather than trusting
IsAbsoluteUri, and rebuild the target as relative soPackUriHelper.ResolvePartUriagrees on both runtimes:A genuinely absolute target (
http://…) is still rejected. On .NET the change is a no-op, sinceIsAbsoluteUriwas alreadyfalsefor these targets.Verification
configheaders read back as0,64,133,132. With this patch →id,value,domain,description.id,value,domain,description(no behaviour change).lib/netstandard2.0assemblies plusSystem.IO.Packaging4.7.0.Minimal repro
Read any Excel-authored
.xlsxwhosexl/_rels/workbook.xml.relscarriesTarget="/xl/sharedStrings.xml", under Mono:Suggested follow-up (not in this PR)
The failure was silent because shared strings are optional and a dropped relationship only lands in
RelationshipCatalog.Issues, which a caller never sees. Consider surfacing discovery issues for parts the reader then skips — a workbook that has asharedStrings.xmlpart but no usable relationship to it is almost certainly a bug worth reporting rather than reading past.Same reporter as the plug-in loader guard shipped in 3.2.0 — thanks for taking that one.