Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML parser segfaults when given an obsContext block #1

Open
joemasiero opened this issue Sep 4, 2024 · 3 comments
Open

XML parser segfaults when given an obsContext block #1

joemasiero opened this issue Sep 4, 2024 · 3 comments

Comments

@joemasiero
Copy link

joemasiero commented Sep 4, 2024

digest2/digest2/d2ades.c

Lines 257 to 280 in 7ebad07

tracklet *parse_ades(const char *filepath) {
/* Load XML document */
xmlDocPtr doc = xmlParseFile(filepath);
if (doc == NULL) {
fprintf(stderr, "Error: unable to parse file \"%s\"\n", filepath);
return NULL;
}
xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc);
xmlXPathObjectPtr optical_nodes = xmlXPathEvalExpression("//ades/optical", xpathCtx);
if (optical_nodes == NULL) {
fprintf(stderr, "Error: Nothing found...");
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc);
return NULL;
}
tracklet *tk = parse_nodes(optical_nodes);
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc);
return tk;

This parser works find when using the sample.xml data file provided. However, when using an ADES file formatted with (an otherwise valid) obsContext block, it reports:

> ./digest2 -p $DIGEST2 test.xml     
Desig.    RMS Int NEO N22 N18 Other Possibilities
zsh: segmentation fault  ./digest2 -p $DIGEST2 test.xml

removing the <obsData>, <obsBlock> and <obsContext> structures and leaving only the <optical> blocks directly under <ades> (instead of inside <obsData> and <obsBlock>) allows this to work as expected.

@joemasiero
Copy link
Author

An additional issue once I overcome the above: If I put in data from a spacecraft (e.g. C58) it parses the tracklets but defines everything as Int=100, NEO=100. However, if I convert the same file to MPC80 and run it again, I get a much more realistic distribution of scores. Perhaps the s/c position isn't being parsed right in the ADES reader? I'll note I'm using geocentric s/c positions for both files

@joemasiero
Copy link
Author

So, if you update this line:

xmlXPathObjectPtr optical_nodes = xmlXPathEvalExpression("//ades/optical", xpathCtx);

to
xmlXPathObjectPtr optical_nodes = xmlXPathEvalExpression("//ades/obsBlock/obsData/optical", xpathCtx);
the code will now parse valid ADES files correctly. Still having the 100-100 problem when reading a valid ADES file

@joemasiero
Copy link
Author

This should be closed by PR #2

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

No branches or pull requests

1 participant