Skip to content

fix: walk parent-view chain before CreateDatabase save#17

Merged
tinysec merged 1 commit into
masterfrom
fix/createdatabase-parent-view-walk
Jul 7, 2026
Merged

fix: walk parent-view chain before CreateDatabase save#17
tinysec merged 1 commit into
masterfrom
fix/createdatabase-parent-view-walk

Conversation

@tinysec

@tinysec tinysec commented Jul 7, 2026

Copy link
Copy Markdown
Owner

BinaryView.CreateDatabase passed its own handle straight to BNCreateDatabase, but a derived view (e.g. the ELF view layered on raw bytes) cannot own a database: BNCreateDatabase must run against the root (raw) parent view. Saving a freshly loaded binary therefore returned false and wrote a truncated 90112-byte database.

Now CreateDatabase walks this.Parent to the root first, matching C++ BinaryView::CreateDatabase (binaryview.cpp:1673) and Python FileMetadata.create_database (which passes self.raw.handle). SaveAutoSnapshot is unchanged: C++ SaveAutoSnapshot does not walk the parent, passing this directly.

Reproduced against the official Python binding: bv.create_database(...) succeeds (valid 675840-byte .bndb); the C# call failed before this fix and succeeds after.

Verification: added a regression test (CreateDatabaseRoundTripTests) that opens cat.bndb (ELF view with a Raw parent), saves a temp .bndb, reloads it, and asserts the functions survive. Confirmed it fails without this fix and passes with it.

BinaryView.CreateDatabase passed its own handle straight to BNCreateDatabase,
but a derived view (e.g. the ELF view layered on raw bytes) cannot own a
database: BNCreateDatabase must run against the root (raw) parent view. Saving
a freshly loaded binary therefore returned false and wrote a truncated 90112-byte
database.

Now CreateDatabase walks this.Parent to the root first, matching
C++ BinaryView::CreateDatabase (binaryview.cpp:1673) and Python
FileMetadata.create_database (which passes self.raw.handle). SaveAutoSnapshot is
unchanged: C++ SaveAutoSnapshot does not walk the parent, passing 'this' directly.
@tinysec tinysec merged commit cef6187 into master Jul 7, 2026
1 check passed
@tinysec tinysec deleted the fix/createdatabase-parent-view-walk branch July 7, 2026 09:58
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 this pull request may close these issues.

1 participant