Skip to content

bug(obs-util): config-file duplicate section/key lookup diverges from C after uthash bucket expansion #681

Closed

Description

@zackees

Summary

obs_util::config_file resolves duplicate section names and duplicate keys with "newest wins" (find_item in rust/obs-util/src/config_file.rs, .iter().rev().find(..)). The C original uses HASH_FIND_STR over uthash, and the parser adds duplicates with HASH_ADD_STR without looking them up first (parse_config_data, config_add_item in libobs/util/config-file.c). uthash prepends to the bucket chain, so newest wins only until the bucket expands. HASH_EXPAND_BUCKETS (vendored uthash.h around line 866) relinks every chain by prepending into the new buckets, which reverses the order of entries with the same key. After that, HASH_FIND_STR returns an older duplicate.

Reproduction

Found by the new config_ini_diff fuzz target (#144). Minimal input: ten identical section headers, with the key only in the last one:

[s]   (x9)
[s]
k=v
  • C oracle: config_get_string(cfg, "s", "k") returns NULL. The tenth add reaches HASH_BKT_CAPACITY_THRESH (10), the expand reverses the chain, and the lookup lands on the first, empty [s].
  • Rust shim and Config::open_string: return ""/"v" from the last [s].

With 2, 11, 12 or 20 duplicates the results agree. Whether they agree depends on the expand history (expand_mult, ineff_expands/noexpand) and on how the other names hash, so a fixed "first" or "last" rule cannot match C. Duplicate keys inside one section take the same config_add_item path. config_set_item, config_remove_value and config_has_user_value use the same lookup, so writes can also target a different duplicate than C does.

Expected

The Rust port returns the same duplicate as C for every input, as the differential tier requires. That probably means modelling uthash's bucket placement and expansion (Jenkins hash, threshold 10, ineffective-expand cutoff) for duplicate resolution, or keeping one ordered chain per bucket.

Notes

  • Pre-existing behaviour, not caused by the fuzz work. quality: Run the cargo-fuzz differential targets on a schedule #144's target excludes lookups under duplicated section names and duplicated keys and cites this issue. Remove that exclusion when this is fixed.
  • Real global.ini/profile files rarely contain duplicates, but hand-edited or corrupted files can.
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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions