Skip to content

fix(discover): make cbm_gitignore_merge atomic on allocation failure#562

Merged
DeusData merged 1 commit into
mainfrom
fix/493-gitignore-merge-atomic
Jun 22, 2026
Merged

fix(discover): make cbm_gitignore_merge atomic on allocation failure#562
DeusData merged 1 commit into
mainfrom
fix/493-gitignore-merge-atomic

Conversation

@DeusData

Copy link
Copy Markdown
Owner

What does this PR do?

Makes cbm_gitignore_merge atomic on allocation failure.

Previously the merge copied each src pattern into dst one strdup at a time and returned void on failure — leaving dst with a partial set of patterns and no signal to the caller. If the dropped pattern was the critical exclude (the .git/info/exclude entry that prevents an OOM walk, #489), the matcher could end up half-merged with no indication.

Now: on any allocation failure the partial copies are rolled back so dst is left exactly as it was (atomic), and the function returns bool. The .gitignore caller degrades gracefully — the exclude patterns are skipped, as if the file were absent — instead of corrupting the matcher.

This was surfaced during a closer review of the (already-merged) #493.

Test

gi_merge_atomic_on_alloc_failure injects a strdup failure on the 2nd src pattern via a small test seam, then asserts the merge returns false and dst is unchanged (its own pattern still matches; the partially-copied src pattern is gone). It is red without the rollback — the first src pattern leaks into dst.

Checklist

  • Every commit is signed off (git commit -s)
  • New behavior is covered by a reproduce-first test

cbm_gitignore_merge copied src patterns into dst one strdup at a time and
returned void on failure, leaving dst with a partial set of patterns and no
signal to the caller. If the dropped pattern was the critical exclude (the
.git/info/exclude entry that prevents an OOM walk), the bug could silently
recur with some patterns applied and others dropped.

Make the merge atomic: on any allocation failure roll back the partial copies
so dst is left exactly as it was, and return bool so callers can tell. The
.gitignore caller now degrades gracefully (exclude patterns skipped, as if the
file were absent) instead of ending up with a half-merged matcher.

Adds a reproduce-first test that injects a strdup failure mid-merge via a test
seam and asserts dst is unchanged; it is red without the rollback.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
@DeusData DeusData merged commit 684e35b into main Jun 22, 2026
14 checks passed
@DeusData DeusData deleted the fix/493-gitignore-merge-atomic branch June 22, 2026 23:16
@studyzy studyzy mentioned this pull request Jun 23, 2026
5 tasks
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.

1 participant