Skip to content

[Bug]: JSON.ARRPOP treats a non-integer index as -1 and removes the last array element #1713

In review

Description

@carlosqwqqwq

[Bug]: JSON.ARRPOP treats a non-integer index as -1 and removes the last array element

What happened?

When an explicit JSON.ARRPOP index is not an integer, RedisJSON treats it as -1. The command succeeds and removes the final array element instead of rejecting the invalid argument.

Steps to reproduce

Run on a disposable Redis 8.10.3 server with RedisJSON 8.10.0 loaded and an empty logical database. Confirm the key does not exist before running:

EXISTS bug:arrpop-invalid
JSON.SET bug:arrpop-invalid $ '[10,20,30]'
JSON.ARRPOP bug:arrpop-invalid $ not-an-integer
JSON.GET bug:arrpop-invalid $

JSON.SET bug:arrpop-invalid $ '[10,20,30]'
JSON.ARRPOP bug:arrpop-invalid $ 1.5
JSON.GET bug:arrpop-invalid $

DEL bug:arrpop-invalid

Observed behavior

Both invalid indexes return 30; the following JSON.GET returns [[10,20]]. A valid index of -1 also returns 30, showing that both invalid values are treated as the default last index.

Expected behavior

Reject a supplied non-integer index and leave the JSON document unchanged. This report does not depend on a particular error message.

OS

Linux x86_64 (Ubuntu 24.04)

CPU Architecture

x86_64

Redis Server Version

8.10.3

Redis Module Version

RedisJSON 8.10.0

Docker Installation

Tested with Redis Open Source 8.10.3 and its bundled RedisJSON module; no standalone RedisJSON Docker Hub release was used.

  • I installed the dockerhub release

Relevant log output

No separate server log excerpt; the command replies above are the relevant output.

Additional context

The command schema defines index as an integer. In the tested RedisJSON source, the optional index parser uses args.next_i64().unwrap_or(-1), so a parse failure is treated the same as an omitted argument: index parsing and argument metadata.

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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions