Skip to content

Commit

Permalink
Fixed: Concurrency Issue in repacking partial SOLIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Jul 23, 2024
1 parent 7573429 commit 5914488
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions NexusMods.Archives.Nx/FileProviders/FromExistingNxBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public IFileData GetFileData(ulong start, ulong length)
throw new Exception("Repeated call to GetData. This is not allowed.");

_hasCalledGetData = true;

if (start != 0 || length != FileSize)
throw new InvalidOperationException("This provider only supports reading the entire file.");
#endif

return new DecompressedNxBlockFileData(LazyRefCounterDecompressedNxBlock, DecompressedBlockOffset, FileSize);
Expand Down Expand Up @@ -200,16 +203,17 @@ public void ConsiderFile(FileEntry entry)
return _data;

// Not much contention expected so full lock is ok, no need for extra field and 'cmpxchg' here.
lock (this)
lock (_sourceNxDataProvider)
{
// Another thread might have already initialized in lock.
if (_data != null)
return _data;

_data = AllocNativeMemory((nuint)_numBytesToDecompress);
var data = AllocNativeMemory((nuint)_numBytesToDecompress);
using var rawBlockData = _sourceNxDataProvider.GetFileData(_blockOffset, _compressedBlockLength);
Compression.Decompress(_compression, rawBlockData.Data, (int)rawBlockData.DataLength, (byte*)_data, (int)_numBytesToDecompress);
return _data;
Compression.Decompress(_compression, rawBlockData.Data, (int)rawBlockData.DataLength, (byte*)data, (int)_numBytesToDecompress);
_data = data;
return data;
}
}

Expand Down

0 comments on commit 5914488

Please sign in to comment.