Fix FileNode crash on terminator / unknown node types (baseType == 2)#28
Open
twortley wants to merge 1 commit into
Open
Fix FileNode crash on terminator / unknown node types (baseType == 2)#28twortley wants to merge 1 commit into
twortley wants to merge 1 commit into
Conversation
FileNode.__init__ dereferenced self.data.ref for any node whose header baseType == 2 (a reference node), but the dispatch chain's final `else` branch left self.data unset for unrecognised / terminator node IDs, so those nodes raised `AttributeError: 'FileNode' object has no attribute 'data'`. The real-world trigger is a FileNodeListFragment terminator (file_node_id 0 with non-zero upper bits, seen in large / heavily-revised .one files): the fragment loop breaks on id 0/255, but only after the node is constructed, so the crash beats the guard. Fix: default self.data to None for unknown node types, and only recurse into a child FileNodeList when self.data is set. Adds a self-contained regression test (4-byte header, no sample file needed). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
FileNode.__init__raisesAttributeError: 'FileNode' object has no attribute 'data'on some valid.onefiles, aborting the whole parse.It happens for any FileNode whose header
baseType == 2(a reference node) but whosefile_node_idisn't in_FileNodeIDs(sofile_node_typeresolves to"Invalid"). The dispatch chain's finalelsebranch (p = 1) never setsself.data, and the next block then dereferencesself.data.reffor reference nodes.The real-world trigger is a
FileNodeListFragmentterminator. The fragment loop breaks onfile_node_id in (0, 255)— but only after the node is constructed:So a terminator whose upper header bits encode
baseType == 2crashes during construction, before the loop can break. Larger / heavily-revised sections hit this; small files usually terminate cleanly.Fix
Default
self.data = Nonefor unknown node types, and only recurse into a childFileNodeListwhenself.data is not None. Known reference nodes are unaffected, and the fragment loop's existing terminator-break then ends the fragment cleanly.Test
Adds a self-contained regression test: a 4-byte FileNode header (
id=0, baseType=2) reproduces the crash with no sample.onefile needed.Found while building an offline OneNote→Markdown exporter — this crash blocked parsing of several large real notebooks. Thanks for pyOneNote!