ydb_get_s() / ydb_get_st() issue LVUNDEF error if specified local variable does not exist
Final Release Note
ydb_get_s()
/ ydb_get_st()
return a YDB_ERR_LVUNDEF error on a non-existent local variable node specified with a large number of subscripts or very large subscripts, and sets $ZSTATUS, which can subsequently be accessed with ydb_zstatus()
which will contain the first 512 bytes of the ZWRITE representation of the local variable node. In releases starting with r1.26, the process in rare cases (if the ZWRITE format representation of the local variable node approached or exceeded 512 bytes) terminated with a GTMASSERT2 error. This was discovered in the YottaDB development environment and never reported by a user.[#843 (closed)]
Description
This is a pre-existing issue in the Simple API that we found by analyzing a random test failure in the YDBRust pipeline (see https://gitlab.com/YottaDB/Lang/YDBRust/-/jobs/2042901151 for original failure which did not leave any artifacts). While the original failure did not leave any indication as to what random data caused the failure, in-house attempts at reproducing the failure succeeded and eventually a simple test case was obtained.
Attached is that simple test case ydbgets.c
that produces a fatal %YDB-F-GTMASSERT2
error when compiled and run.
$ gcc -g ydbgets.c `pkg-config --libs --cflags yottadb` -o ydbgets ; ./ydbgets
%YDB-F-GTMASSERT2, YottaDB r1.32 Linux x86_64 - Assert failed sr_port/format2zwr.c line 286 for expression (max_len > dstlen)
If I make a small change to ydbgets.c
at line 30 to not pass in the 3rd subscript (diff of change shown below) in ydbgets2.c
and compile/run it I get the expected %YDB-E-LVUNDEF
error message.
$ diff ydbgets.c ydbgets2.c
30c30
< status = ydb_get_s(&varname, 3, sub, &ret);
---
> status = ydb_get_s(&varname, 2, sub, &ret);
$ gcc -g ydbgets.c `pkg-config --libs --cflags yottadb` -o ydbgets; ./ydbgets
150373850,(SimpleAPI),%YDB-E-LVUNDEF, Undefined local variable: x("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","A")
This is a regression in ydb_get_s()
introduced in r1.26 (as part of fixing #431 (closed) in !598 (merged)) that a random test case in the YDBRust project eventually exposed.