Skip to content

Fix TOCTOU race condition in XLiffBody.AddTransUnitRaw#154

Merged
imnasnainaec merged 8 commits into
masterfrom
fix/150-toctou-addtransunitraw
Jun 15, 2026
Merged

Fix TOCTOU race condition in XLiffBody.AddTransUnitRaw#154
imnasnainaec merged 8 commits into
masterfrom
fix/150-toctou-addtransunitraw

Conversation

@imnasnainaec

@imnasnainaec imnasnainaec commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Moves the duplicate-ID check and _transUnitDict write inside the SpinLock try block, closing the TOCTOU window where two threads with the same ID could both pass the check and silently overwrite each other's entry
  • Makes _transUnitIdLock instance-level (removes static) so concurrent operations on different XLiffBody instances no longer contend on a shared lock
  • Replaces Interlocked.Increment with ++ inside the SpinLock critical section, where the lock already provides mutual exclusion
  • Documents in RemoveTransUnit why _transUnitIdLock is intentionally not acquired there

Closes #150

Devin review: https://app.devin.ai/review/sillsdev/l10nsharp/pull/154


This change is Reviewable

…pinLock (#150)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Test Results

    7 files  ±0  104 suites  ±0   37s ⏱️ +14s
166 tests ±0  161 ✔️ ±0    5 💤 ±0  0 ±0 
630 runs  ±0  615 ✔️ ±0  15 💤 ±0  0 ±0 

Results for commit 18f906a. ± Comparison against base commit 7c4190e.

♻️ This comment has been updated with latest results.

@imnasnainaec imnasnainaec self-assigned this Jun 8, 2026
@imnasnainaec imnasnainaec marked this pull request as draft June 8, 2026 17:29
@imnasnainaec imnasnainaec marked this pull request as ready for review June 8, 2026 18:11

@andrew-polk andrew-polk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrew-polk reviewed 2 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on imnasnainaec).

@imnasnainaec imnasnainaec enabled auto-merge (squash) June 15, 2026 18:08
@imnasnainaec imnasnainaec merged commit d8b165c into master Jun 15, 2026
4 of 5 checks passed
@imnasnainaec imnasnainaec deleted the fix/150-toctou-addtransunitraw branch June 15, 2026 18:10
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.

TOCTOU race condition in XLiffBody.AddTransUnitRaw

2 participants