IGListKit/Source
Cameron Roth 54605c079a
Some checks failed
IGListKit CI / Run Danger (push) Has been cancelled
IGListKit CI / Unit Test macOS (push) Has been cancelled
IGListKit CI / Unit Test tvOS (push) Has been cancelled
IGListKit CI / Build Examples and UI tests. (push) Has been cancelled
IGListKit CI / CocoaPods Lint (push) Has been cancelled
IGListKit CI / Verify generate_spm_sources_layout.sh is not broken (push) Has been cancelled
IGListKit CI / Verify SPM build by invoking `xcodebuild` on Package.swift (push) Has been cancelled
IGListKit CI / Unit Test iOS (push) Has been cancelled
IGListKit CI / Verify Carthage build XCFramework (push) Has been cancelled
Fix heap corruption crash from concurrent array mutation during diff (#1578)
Summary:
Fixes https://github.com/Instagram/IGListKit/issues/1578

Callers of `IGListDiff`/`IGListDiffPaths` may pass `NSMutableArray` instances backed by collections that are mutated on other threads. Because the diffing algorithm uses `__unsafe_unretained` pointers internally for performance, concurrent mutation can cause use-after-free heap corruption — typically manifesting as:

```
malloc: Incorrect checksum for freed object: probably modified after being freed.
```

inside `std::deque::push_back` during the entry `oldIndexes` stack growth.

This change adds `[oldArray copy]` and `[newArray copy]` at the top of `IGListDiffing()`. For immutable `NSArray` inputs this is a no-op retain with zero overhead. For `NSMutableArray` inputs it creates an immutable snapshot, narrowing the race window from the entire O(n+m) diff to just the `-copy` call.

This is a best-effort mitigation — callers are still responsible for not mutating the source array concurrently since `-[NSMutableArray copy]` itself is not atomic.

Differential Revision: D101205956

fbshipit-source-id: 514ebbef1903c796c10fee23f4efb4dd9b3073bd
2026-04-30 21:33:49 -07:00
..
IGListDiffKit Fix heap corruption crash from concurrent array mutation during diff (#1578) 2026-04-30 21:33:49 -07:00
IGListKit Replace IGFailAssert with NSLog for delegate recursion checks 2026-04-16 16:42:39 -07:00
IGListSwiftKit General fixes to restore GitHub CI (#1622) 2025-03-14 23:56:06 -07:00
Info.plist Updated the IGListKit docs to v5.2.0 (#1656) 2026-02-16 23:54:31 -08:00