elrnv / vtkio

Visualization ToolKit (VTK) file parser and writer
Apache License 2.0
56 stars 13 forks source link

Error importing VTU with `<AppendedData encoding="raw">` block #27

Open w1th0utnam3 opened 1 year ago

w1th0utnam3 commented 1 year ago

The attached file fluid_1_91.vtu cannot be loaded using v0.6.0 or the release-0.7 branch and results in the errors:

XML error: Deserialization error: Xml(UnexpectedEof("</Err(Utf8Error { valid_up_to: 0, error_len: Some(1) })>"))
Deserialization error: Xml(UnexpectedEof("</Err(Utf8Error { valid_up_to: 0, error_len: Some(1) })>"))
Unexpected EOF during reading </Err(Utf8Error { valid_up_to: 0, error_len: Some(1) })>.
Unexpected EOF during reading </Err(Utf8Error { valid_up_to: 0, error_len: Some(1) })>.

while Paraview is able to load the file.

The file uses a <AppendedData encoding="raw">...</AppendedData> raw binary block for all the data arrays and I suspect it happens to contain characters or sequences that confuse the XML parser.

The file fluid_1_91_encoded.vtu can be read without problems after opening the original file in Paraview and re-exporting it to VTU with the option "Encode appended data" which I guess applies base64 encoding.

I don't know if it is possible to somehow use different options for the XML parser to support the raw binary block or whether this is actually not allowed by the XML format and would require manual parsing.

fluid_1_91.zip

elrnv commented 1 year ago

Thank you for this issue! Indeed officially the XML format doesn't support binary data, and this is actually what is blocking the 0.7 release currently. The plan is to upstream a feature into quick-xml that allows one to implement a custom parser for the text in XML files. The example file you provided should be very helpful in addressing testing binary support.

w1th0utnam3 commented 1 year ago

Ah right. I missed that in the version 0.7 PR. I guess this is related to this quick-xml PR then: https://github.com/tafia/quick-xml/pull/555

Hope the sample file helps!

elrnv commented 1 year ago

Yes exactly! Thanks for linking that issue.

DanW97 commented 2 months ago

Has https://github.com/tafia/quick-xml/pull/783 managed to resolve blockers on the new release? Or is there more work required to support <AppendedData encoding="raw">-containing vtk files?

elrnv commented 2 months ago

Sadly not yet, because we use the serde API for dealing with XML files here, we also need to extend the serde API to support binary blobs in quick-xml. I started a PR here but don't have much time to finish it. Any help is appreciated of course! I am happy to help any efforts there.

DanW97 commented 2 months ago

That's unfortunate. I haven't got loads of time but I am willing to try, if I can be pointed in the right direction for what's needed to finish it. Is it a case of fixing the failing tests or is there more to it?