Skip to content

bug(sql): paging offset int overflow throws or silently returns first page #2432

Description

@Aias00

Description

DefaultSQLExecutor.executeSQL/executeSQLStreaming compute Integer offset = (pageNo - 1) * pageSize using int arithmetic with no bounds validation. pageNo/pageSize are client-controlled Integer (only the AI/MCP tool path clamps via normalizePageSize; the main execution path does not). A large pageNo (e.g. > ~2.1M with default pageSize 1000) wraps the int to a small or negative value: setMaxRows(negative) throws SQLException (500); setMaxRows(smallPositive) silently caps the result set and generateDataList skips offset rows, returning first-page data for a huge page number with no error.

Location

chat2db-community-spi/.../DefaultSQLExecutor.java:836-838 (executeSQL), :913-915 (executeSQLStreaming); :247-249/:1001-1003/:1081-1085 (stmt.setMaxRows(offset + count)). MAX_PAGE_SIZE = 1000 is a default, not an input cap.

Impact

Large/buggy page numbers cause either a 500 or silently wrong (first-page) results with no indication.

Suggested fix

Clamp pageNo >= 1, pageSize to [1, MAX_PAGE_SIZE], and pageNo to <= Integer.MAX_VALUE / pageSize so (pageNo - 1) * pageSize (and offset + count) fit in int — preventing both the negative-setMaxRows throw and the silent wrong-page return.

Related existing

None.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions