[BUG] SQL returns 500 StringIndexOutOfBoundsException for an empty cursor

Open Beginner friendly
#5,983 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
api

Research direction

The failure comes from RestSqlAction.isLegacyCursor, which calls cursor.substring(0, 1) without checking for an empty string (around line 251 of RestSqlAction.java). Both _plugins/_sql and _plugins/_sql/close route through this class. Reproduce by POSTing {"cursor": ""} to each endpoint, then add an empty-cursor guard that returns HTTP 400. Done when both endpoints return 400 for an empty cursor and a test covers it.

Written by the indexing model from the issue text.

Description

bug untriaged

What is the bug?
A request with an empty cursor returns HTTP 500 with StringIndexOutOfBoundsException. This is a bad request, so it should return 400.

How can one reproduce the bug?

POST _plugins/_sql
{"cursor": ""}
{
  "error": {
    "reason": "There was internal problem at backend",
    "details": "Range [0, 1) out of bounds for length 0",
    "type": "StringIndexOutOfBoundsException"
  },
  "status": 500
}

POST _plugins/_sql/close with the same body returns the same 500.

What is the expected behavior?
HTTP 400 with a message that the cursor is empty or invalid.

What is your host/environment?

  • main at 135d7db4d (3.10.0-SNAPSHOT), local integTest cluster
  • Plugins: opensearch-sql

Do you have any additional context?
RestSqlAction.isLegacyCursor calls cursor.substring(0, 1) without checking for an empty string (line 251). Both endpoints are handled by RestSqlAction.

Dominant language
Java
Stars
176
Forks
237
Avg merge
2d 12h
Merged PRs (30d)
34

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from opensearch-project/sql

All issues in opensearch-project/sql

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.