Skip to content

fix: Handle non utf-8 characters in OME-XML - #141

Merged
weiji14 merged 2 commits into
mainfrom
ome-xml/non-utf8
Dec 7, 2025
Merged

weiji14 merged 2 commits into
mainfrom
ome-xml/non-utf8

Conversation

@weiji14

@weiji14 weiji14 commented Nov 22, 2025 •

Copy link
Copy Markdown
Member

By using String::from_utf8_lossy.

Changes:

Fixes #101

By using String::from_utf8_lossy. Changed to another sample OME-TIFF file, and increased prefetch bytes to more than 32kb to avoid hanging when parsing the StripOffsets tag.
@kylebarron

Copy link
Copy Markdown
Member

Ok so to clarify the spec says that these characters should always be UTF8? And which spec are we talking about? TIFF or OME-TIFF?

This tag type is named Value:Ascii, so it seems like a mismatch that we're hitting utf8 issues. Should we rename that to Value::Text? or Value::String?

Alternatively we could store a Vec<u8> but if this is string data, then Vec<u8> seems improper

@weiji14

weiji14 commented Dec 6, 2025

Copy link
Copy Markdown
Member Author

Ok so to clarify the spec says that these characters should always be UTF8? And which spec are we talking about? TIFF or OME-TIFF?

OME-TIFF spec says so, see https://docs.openmicroscopy.org/ome-model/5.6.3/ome-tiff/specification.html

This tag type is named Value:Ascii, so it seems like a mismatch that we're hitting utf8 issues. Should we rename that to Value::Text? or Value::String?

I think this type is something in the TIFF spec, but not 100% sure. Probably ok to just keep it as ASCII.

Alternatively we could store a Vec<u8> but if this is string data, then Vec<u8> seems improper

Yeah, I reckon using a String is better here, otherwise users will need to decode bytes to string...

@weiji14
weiji14 marked this pull request as ready for review December 6, 2025 15:05
@weiji14
weiji14 merged commit 6c962b6 into main Dec 7, 2025
@weiji14
weiji14 deleted the ome-xml/non-utf8 branch December 7, 2025 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OME-TIFF: Result::unwrap() on an Err value: General("invalid utf-8 sequence of 1 bytes from index 2144")

2 participants