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

feat: raise slightly better error when the object in S3 is too short #91

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion sqlite_s3_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def sqlite_s3_query_multi(url, get_credentials=lambda now: (
SQLITE_NOTFOUND = 12
SQLITE_ROW = 100
SQLITE_DONE = 101
SQLITE_IOERR_SHORT_READ = 522
SQLITE_TRANSIENT = c_void_p(-1)
SQLITE_OPEN_READONLY = 0x00000001
SQLITE_OPEN_NOMUTEX = 0x00008000
Expand Down Expand Up @@ -208,7 +209,13 @@ def x_read(p_file, p_out, i_amt, i_ofst):
set_pending_exception(exception)
return SQLITE_IOERR

if offset != i_amt:
if offset < i_amt:
# The SQLite docs strongly suggest to fill unused with zeroes
remainder = i_amt - offset
memmove(p_out + offset, b'\0' * remainder, remainder)
return SQLITE_IOERR_SHORT_READ

if offset > i_amt:
return SQLITE_IOERR

return SQLITE_OK
Expand Down
4 changes: 2 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def test_short_db_header(self):
'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
None,
), get_libsqlite3=get_libsqlite3) as query:
with self.assertRaisesRegex(SQLiteError, 'disk I/O error'):
with self.assertRaisesRegex(SQLiteError, 'not a database'):
query("SELECT * FROM non_table").__enter__()

def test_bad_db_header(self):
Expand All @@ -471,7 +471,7 @@ def test_bad_db_header(self):
'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
None,
), get_libsqlite3=get_libsqlite3) as query:
with self.assertRaisesRegex(SQLiteError, 'disk I/O error'):
with self.assertRaisesRegex(SQLiteError, 'not a database'):
query("SELECT * FROM non_table").__enter__()

def test_bad_db_first_page(self):
Expand Down
Loading