Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions dissect/database/sqlite3/sqlite3.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,27 @@ def raw_page(self, num: int) -> bytes:
if (num < 1 or num > self.header.page_count) and self.header.page_count > 0:
raise InvalidPageNumber("Page number exceeds boundaries")

# If a specific WAL checkpoint was provided, use it instead of the on-disk page.
data = None
if self.checkpoint is not None and (frame := self.checkpoint.get(num)):
return frame.data
# If a specific WAL checkpoint was provided, use it instead of the on-disk page.
data = frame.data

# Check if the latest valid instance of the page is committed (either the frame itself
# is the commit frame or it is included in a commit's frames). If so, return that frame's data.
if self.wal:
elif self.wal:
# Check if the latest valid instance of the page is committed (either the frame itself
# is the commit frame or it is included in a commit's frames). If so, return that frame's data.
for commit in reversed(self.wal.commits):
if (frame := commit.get(num)) and frame.valid:
return frame.data
data = frame.data
break

if data is not None:
if num == 1:
# Page 1 has a database header that needs to be stripped
return data[len(c_sqlite3.header) :]
return data

# Else we read the page from the database file.
if num == 1: # Page 1 is root
if num == 1: # Page 1 is root, skip header
self.fh.seek(len(c_sqlite3.header))
else:
self.fh.seek((num - 1) * self.page_size)
Expand Down