fix(ergasia,exousia): ref-count shared torrent_ids and constant-time login miss-path (#536, #540) - #572
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two verified fixes from the 2026-07-03 deep-audit workflow (adversarially verified + Opus-judged).
#536 — deleting one download destroyed a sibling's live torrent (ergasia). librqbit dedups a duplicate info-hash onto one
torrent_id(returnsAlreadyManaged), so twoDownloadIds could map to the sametorrent_id;delete_torrentthen unconditionally calledsession.delete()on that shared id, destroying the other download's still-live torrent until a restart reconcile pruned it. Added atorrent_refcounts: DashMap<usize, usize>reverse index:acquire_torrent_refon every mapping insert (add, delete-failure restore, reconcile-from-disk),release_torrent_refon delete.session.delete()now runs only when the ref count hits zero; an earlier owner just drops its own mapping entry and leaves the torrent live. The decrement-and-test runs entirely inside DashMap'sEntryshard lock, so two concurrent releases for onetorrent_idcan never both observe "last reference". Regression test (multi_thread) registers two DownloadIds onto one torrent_id, deletes the first, asserts the second's stats still resolve and the librqbit torrent is still present, then deletes the second and asserts it's gone.#540 — login timing side-channel enabled username enumeration (exousia, SECURITY / CWE-203).
login()returnedInvalidCredentialsimmediately on a username miss but ran a full Argon2id verify when the username existed, so response latency alone distinguished existing from non-existing accounts. Fixed by routing both branches through a singleverify_passwordcall: against the real hash when the row exists, otherwise against a fixed precomputed Argon2id sentinel hash (defaultm=19456,t=2,p=1params matchinghash_password), so a non-existent (or too-corrupt-to-convert) username costs the same Argon2id work and wall-clock time as a real wrong-password attempt. The verify runs before theis_activecheck, keeping inactive accounts indistinguishable too. A#[cfg(test)]thread-local verify-call spy proves both miss-paths exercise exactly one Argon2id verify; a third test guards that the sentinel constant parses as valid PHC and never matches.Gate:
kanon gate --fullgreen — fmt, check, clippy (-D warnings), nextest 1919 passed, deny, kanon lint (0/0/0). Two gate iterations fixed acollapsible_if, adeprecated-termlint, and ano-silent-result-swallowat root (not suppressed).Gate-Passedtrailer stamped.Closes #536
Closes #540