Skip to content

Conversation

@hendrikmuhs
Copy link
Contributor

@hendrikmuhs hendrikmuhs commented Sep 28, 2025

Fix a corner case when a kv dict is empty and being iterated over.

  • initialize labels on position 0 and 1, to prevent lookup[1]
    • this works backwards compatible: old keyvi versions reading dicts from new version
  • set start_state to 0 if dict is empty and check start_state !=0 for lookup
    • this works backwards compatible: new keyvi versions reading dicts from old version
    • shortcut lookup on empty dicts to prevent paging for empty dicts

fixes #360

[1] A transition is valid if labels[start_state + c] == c, we ran into this issue because for start_state = 1 the check looks like this: labels[1 + 0] == 0 - As labels are initialized with 0 - and because for empty dicts we write nothing, we had a transition that should not exist. This gets fixed by initializing labels[0](bonus) and labels[0] to something >1. For non-empty dicts construction takes care of setting labels[x], so no illegal state gets introduced.

@hendrikmuhs hendrikmuhs marked this pull request as ready for review September 28, 2025 21:11
@hendrikmuhs hendrikmuhs merged commit 6ea136e into KeyviDev:master Oct 2, 2025
26 of 28 checks passed
@hendrikmuhs hendrikmuhs deleted the empty-kv-dump-bug branch October 2, 2025 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Getting all items, pythons items() can segfault for empty dictionaries

1 participant