Update nesting level data type from u16 to u32 to avoid attempt to add with overflow panic#934
Closed
gliderkite wants to merge 1 commit intotafia:masterfrom
Closed
Update nesting level data type from u16 to u32 to avoid attempt to add with overflow panic#934gliderkite wants to merge 1 commit intotafia:masterfrom
gliderkite wants to merge 1 commit intotafia:masterfrom
Conversation
…d with overflow panics
Collaborator
|
Hm, overflow here means that you have XML with 65535 nested tags. That seems very unlikely. Can you share XML which trigger this error? |
Collaborator
|
Actually, I think, you hit #597 |
Author
No, I cannot share the original full file(s). We are talking about traffic data for whole countries, that may contain sensitive data. This panic is actually quite likely to occur depending on the size of the file. The file is not strictly needed to replicate the issue anyway, you can try with something like this: #[test]
fn test_deserialize_large_publication() {
const SITUATION: &str = r#"<situation id="TTI-756fxxxxxxxx-48c0-47b1-a219-0d66b5c461cd-TTU36310151436002000">
<headerInformation>
<confidentiality>internalUse</confidentiality>
<informationStatus>real</informationStatus>
<urgency>normalUrgency</urgency>
</headerInformation>
<situationRecord xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="NetworkManagement" id="TTI-756f6290-48c0-47b1-a219-0d66b5c461cd-TTUXXXXXXXXXX151436002000-1">
<situationRecordCreationTime>2050-02-09T21:00:00Z</situationRecordCreationTime>
<situationRecordVersion>1</situationRecordVersion>
<situationRecordVersionTime>2026-02-03T14:55:11Z</situationRecordVersionTime>
<situationRecordFirstSupplierVersionTime>2050-02-03T14:55:11Z</situationRecordFirstSupplierVersionTime>
<probabilityOfOccurrence>certain</probabilityOfOccurrence>
<validity>
<validityStatus>suspended</validityStatus>
<validityTimeSpecification>
<overallStartTime>2050-02-09T21:00:00Z</overallStartTime>
<overallEndTime>2050-02-10T05:00:00Z</overallEndTime>
</validityTimeSpecification>
</validity>
<generalPublicComment>
<comment>
<value lang="EN">Lane closure scheduled due to Roadworks / License - Roadworks works</value>
</comment>
</generalPublicComment>
<groupOfLocations>
<locationContainedInGroup xsi:type="Linear">
<locationExtension>
<openlr>
<binary version="3">CwV9qyHNxjv+AwAZAMQ74AH//gBOO/8A//8AFjvgCgKdAEQ7FQ==</binary>
</openlr>
</locationExtension>
</locationContainedInGroup>
</groupOfLocations>
<situationRecordExtension>
<alertCEventCode>500</alertCEventCode>
</situationRecordExtension>
<networkManagementType>laneOrCarriagewayClosed</networkManagementType>
</situationRecord>
</situation>"#;
let mut situations = String::new();
for _ in 0..30_000 {
situations.push_str(SITUATION);
}
let xml = d2_logical_model_xml(&situations);
let model: D2LogicalModel = quick_xml::de::from_reader(xml.as_slice()).unwrap();
}
fn d2_logical_model_xml(situations: &str) -> Vec<u8> {
format!(
r#"
<?xml version="1.0" encoding="UTF-8" ?>
<d2LogicalModel xmlns="http://datex2.eu/schema/1_0/1_0" modelBaseVersion="1.0">
<payloadPublication xsi:type="SituationPublication">
<publicationTime>2023-10-10T12:44:30Z</publicationTime>
{situations}
</payloadPublication>
</d2LogicalModel>
"#
)
.into_bytes()
} |
Collaborator
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.
I need to parse large XML files (50MB+) that represent traffic information following the DATEX II schema. The content of the XML looks like this:
There can be several thousands of
<situation>. I deserialize usingquick_xmlversion 0.39 into custom struct:But when I attempt to do so with the largest files I get a panic:
This is the line that caused it
where
nesting_levelis au16that ends up overflowing.This patch fixes the issue by simply moving to
u32. I am not familiar with this library so I am not sure if there are other implications, please feel free to suggest better alternatives. As a workaround I can use my fork with this commit or I could stream all the situations and deserialize one by one using this version of the library, but I'd rather avoid that.