-
-
Notifications
You must be signed in to change notification settings - Fork 33k
Open
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-sqlite3type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
If you run the following code, which uses fetchmany(0), you see it will act like fetchall by fetching everything instead of just returning an empty list, hypothetically, this could even be a security exploit if mismanaged.
This code was tested on both python 3.12.0 and python 3.13.7
import sqlite3
# setup
conn = sqlite3.connect(":memory:")
conn.execute('CREATE TABLE IF NOT EXISTS example_table (id INTEGER PRIMARY KEY);')
conn.execute('INSERT INTO example_table (id) VALUES (1), (2), (3);')
conn.commit()
# bug
cursor = conn.execute('SELECT id FROM example_table;')
ids = cursor.fetchmany(0)
print(ids) # Expected: [], Actual: [(1,), (2,), (3,)]
remaining = cursor.fetchall() # will be []
print(remaining)
"""
TERMINAL EXECUTION ON WINDOWS (CMD):
>python test.py
[(1,), (2,), (3,)]
[]
"""
CPython versions tested on:
3.12, 3.13
Operating systems tested on:
Windows
Linked PRs
Metadata
Metadata
Assignees
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-sqlite3type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Status
No status