diff --git a/sqlite_s3_query.py b/sqlite_s3_query.py index 51ff61b..009a098 100644 --- a/sqlite_s3_query.py +++ b/sqlite_s3_query.py @@ -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 @@ -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 diff --git a/test.py b/test.py index 5e199b4..8184c17 100644 --- a/test.py +++ b/test.py @@ -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): @@ -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):