https://bugs.openldap.org/show_bug.cgi?id=9723
Issue ID: 9723 Summary: C_EOF not reset in mdb_cursor_get with MDB_FIRST_DUP Product: LMDB Version: unspecified Hardware: All OS: All Status: UNCONFIRMED Keywords: needs_review Severity: normal Priority: --- Component: liblmdb Assignee: bugs@openldap.org Reporter: stephan.j.bircher@gmail.com Target Milestone: ---
I'm on the master branch of lmdb.
Steps to reproduce
// search for an non-existent key rc = mdb_cursor_get(cursor, &key, &val, MDB_SET_RANGE); if (rc == MDB_NOTFOUND) { // C_EOF is not set on the cursor flags
// go to the last. // C_EOF remains set which is ok mdb_cursor_get(mdbCursor, &key, &val, MDB_LAST);
// go to the first dup of the last // C_EOF remains set which is NOT OK mdb_cursor_get(mdbCursor, &key, &val, MDB_FIRST_DUP);
// return MDB_NOTFOUND in any case whether there are duplicates or not // because C_EOF was not cleared mdb_cursor_get(mdbCursor, &key, &val, MDB_NEXT_NODUP); }
Possible fix:
case MDB_FIRST_DUP: mfunc = mdb_cursor_first; mmove: if (data == NULL || !(mc->mc_flags & C_INITIALIZED)) { rc = EINVAL; break; } if (mc->mc_xcursor == NULL) { rc = MDB_INCOMPATIBLE; break; } if (mc->mc_ki[mc->mc_top] >= NUMKEYS(mc->mc_pg[mc->mc_top])) { mc->mc_ki[mc->mc_top] = NUMKEYS(mc->mc_pg[mc->mc_top]); rc = MDB_NOTFOUND; break; } { MDB_node *leaf = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]); if (!F_ISSET(leaf->mn_flags, F_DUPDATA)) { MDB_GET_KEY(leaf, key); rc = mdb_node_read(mc, leaf, data); break; } } if (!(mc->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED)) { rc = EINVAL; break; } rc = mfunc(&mc->mc_xcursor->mx_cursor, data, NULL); // FIX: clear C_EOF if (rc == MDB_SUCCESS && mc->mc_flags & C_EOF && mfunc == mdb_cursor_first) { mc->mc_flags ^= C_EOF; } break;
https://bugs.openldap.org/show_bug.cgi?id=9723
--- Comment #1 from stephan.j.bircher@gmail.com --- CORRECTION:
// search for an non-existent key rc = mdb_cursor_get(cursor, &key, &val, MDB_SET_RANGE); if (rc == MDB_NOTFOUND) { // C_EOF is set on the cursor flags
https://bugs.openldap.org/show_bug.cgi?id=9723
Howard Chu hyc@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |IN_PROGRESS Ever confirmed|0 |1
--- Comment #2 from Howard Chu hyc@openldap.org --- (In reply to stephan.j.bircher from comment #0)
I'm on the master branch of lmdb.
Thanks for the report. I believe the fix is simpler than that. https://git.openldap.org/openldap/openldap/-/merge_requests/428
Please test, thanks.
https://bugs.openldap.org/show_bug.cgi?id=9723
Quanah Gibson-Mount quanah@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |0.9.30 Keywords|needs_review |
https://bugs.openldap.org/show_bug.cgi?id=9723
--- Comment #3 from stephan.j.bircher@gmail.com --- Should clearing C_EOF not only happen after a successful mdb_cursor_first()?
https://bugs.openldap.org/show_bug.cgi?id=9723
--- Comment #4 from Howard Chu hyc@openldap.org --- (In reply to stephan.j.bircher from comment #3)
Should clearing C_EOF not only happen after a successful mdb_cursor_first()?
The DB has already been determined to be non-empty, which is all that C_EOF is meant to signal.
https://bugs.openldap.org/show_bug.cgi?id=9723
--- Comment #5 from stephan.j.bircher@gmail.com --- (In reply to Howard Chu from comment #4)
(In reply to stephan.j.bircher from comment #3)
Should clearing C_EOF not only happen after a successful mdb_cursor_first()?
The DB has already been determined to be non-empty, which is all that C_EOF is meant to signal.
Great! Thanks for the clarification. I will test and give feedback...
https://bugs.openldap.org/show_bug.cgi?id=9723
--- Comment #6 from stephan.j.bircher@gmail.com --- My tests are passing.
https://bugs.openldap.org/show_bug.cgi?id=9723
--- Comment #7 from Howard Chu hyc@openldap.org --- (In reply to stephan.j.bircher from comment #6)
My tests are passing.
Great, thanks for confirming.
https://bugs.openldap.org/show_bug.cgi?id=9723
Quanah Gibson-Mount quanah@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|IN_PROGRESS |RESOLVED Resolution|--- |FIXED
--- Comment #8 from Quanah Gibson-Mount quanah@openldap.org --- • 55fd54da by Howard Chu at 2021-10-25T17:17:42+01:00 ITS#9723 clear C_EOF on cursor with MDB_FIRST_DUP
https://bugs.openldap.org/show_bug.cgi?id=9723
--- Comment #9 from Quanah Gibson-Mount quanah@openldap.org --- RE0.9:
• c4085fdf by Howard Chu at 2021-10-26T16:40:38+01:00 ITS#9723 clear C_EOF on cursor with MDB_FIRST_DUP