Skip to content

Unexpected error when using select or pairs with after #11221

@locker

Description

@locker

Bug description

Using select or pairs with after given as a tuple or table may result in unexpected errors.

The problem is that when we encode after we reuse the same buffer we used for encoding key without taking account the fact that it may be relocated:

local ibuf = cord_ibuf_take()
local key, key_end = tuple_encode(ibuf, key, 2)
local key_is_nil = key + 1 >= key_end
local new_position = nil
local iterator, offset, limit, after, fetch_pos =
check_select_opts(opts, key_is_nil, 2)
local region_svp = builtin.box_region_used()
local nok = not iterator_pos_set(index, after, ibuf, 2)

ibuf:consume(ibuf.wpos - ibuf.rpos)
local tuple, tuple_end = tuple_encode(ibuf, pos, level + 1)

Tarantool version:

Tarantool 3.4.0-entrypoint-168-g26b50791bb16
Target: Linux-x86_64-Debug
Build options: cmake . -DCMAKE_INSTALL_PREFIX=/home/vlad/src/tarantool/tarantool/build/debug/install -DENABLE_BACKTRACE=TRUE
Compiler: GNU-13.2.0
C_FLAGS: -fexceptions -funwind-tables -fasynchronous-unwind-tables -fno-common -msse2 -Wformat -Wformat-security -Werror=format-security -fstack-protector-strong -fPIC -fmacro-prefix-map=/home/vlad/src/tarantool/tarantool=. -std=c11 -Wall -Wextra -Wno-gnu-alignof-expression -fno-gnu89-inline -Wno-cast-function-type -Werror -g -ggdb -O0
CXX_FLAGS: -fexceptions -funwind-tables -fasynchronous-unwind-tables -fno-common -msse2 -Wformat -Wformat-security -Werror=format-security -fstack-protector-strong -fPIC -fmacro-prefix-map=/home/vlad/src/tarantool/tarantool=. -std=c++11 -Wall -Wextra -Wno-invalid-offsetof -Wno-gnu-alignof-expression -Wno-cast-function-type -Werror -g -ggdb -O0

Steps to reproduce

Run the following script:

box.cfg{log_level = 'warn'}
box.space._schema:select({}, {iterator = 'ge', after = {'y'}})
box.space._schema:select({}, {iterator = 'ge', after = {string.rep('y', 100000)}})
os.exit(0)

Actual behavior

The script fails with the error:

2025-03-04 22:45:08.841 [146040] main test.lua:3 E> ER_KEY_PART_COUNT: Invalid key part count (expected [0..1], got 20560)
2025-03-04 22:45:08.841 [146040] main say.c:85 F> fatal error, exiting the event loop

Expected behavior

The script exits without errors.

Metadata

Metadata

Assignees

Labels

3.3Target is 3.3 and all newer release/master branches3.4Target is 3.4 and all newer release/master branches3.5Target is 3.5 and all newer release/master branchesbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions