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

load_xdf should not crash on corrupt footer. #17

Closed
cboulay opened this issue Oct 31, 2023 · 1 comment · Fixed by #19
Closed

load_xdf should not crash on corrupt footer. #17

cboulay opened this issue Oct 31, 2023 · 1 comment · Fixed by #19

Comments

@cboulay
Copy link
Contributor

cboulay commented Oct 31, 2023

Prompted by a user issue here:
labstreaminglayer/App-LabRecorder#107

LabRecorder puts clock offsets in the footer, but it also puts clock offsets throughout the recording. It shouldn't be strictly necessary to process the footer.

load_xdf should gracefully handle a corrupt footer.

Related: xdf-modules/pyxdf#83

@mcvain
Copy link
Contributor

mcvain commented Nov 13, 2023

It seems that load_xdf can open the file just fine if the corrupt element in the XML tree is completely missing. It only crashes because when an element is incomplete, xmlread throws an exception. Therefore the easiest working solution is to just catch and ignore the error:

case 6 % read [StreamFooter] chunk
    % read [StreamId]
    id = idmap(fread(f,1,'uint32'));
    % read [Content]
    try
        footer = parse_xml_struct(fread(f,len-6,'*char')');
        streams{id} = hlp_superimposedata(footer,streams{id});
    catch e
        fprintf('  got error "%s" (%s), ignoring truncated XML structure.\n',e.identifier,e.message);
    end

Similarly, pyxdf.load_xdf crashes on a corrupt XML element in the footer in the exact same way, but works fine if you ignore the XML error:

elif tag == 6:
    # read [StreamFooter] chunk
    xml_string = f.read(chunklen - 6)
    try:
        streams[StreamId]["footer"] = _xml2dict(fromstring(xml_string))
    except Exception as e:
        if type(e).__name__ == 'ParseError':
            logger.error(
                "found likely XDF file corruption (%s), "
                "ignoring corrupted XML element in footer." % e
            )
    else:
        raise

An alternative is to "fix" the footer by looking for the incomplete element and deleting it. This is a solution I may use for myself but since it modifies the file, it probably won't be a good idea to implement into a reader function like load_xdf.

Of course in all of this, I am assuming there is no way to somehow calculate the information missing in the corrupt footer, which would be the true fix. But I didn't see anything wrong with the streams opened this way.

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

Successfully merging a pull request may close this issue.

2 participants