Skip to content

Commit 0c6151d

Browse files
committed
Additional safety checks to prevent writing 0/negative offset values to index files.
1 parent 2b359f2 commit 0c6151d

File tree

1 file changed

+12
-0
lines changed
  • xivModdingFramework/SqPack/FileTypes

1 file changed

+12
-0
lines changed

xivModdingFramework/SqPack/FileTypes/Index.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,12 @@ public async Task<bool> AddFileDescriptor(string fullPath, long dataOffset, XivD
14211421
await AddFileDescriptor(fullPath + ".flag", -1, dataFile, false);
14221422
}
14231423

1424+
if(dataOffset <= 0)
1425+
{
1426+
// Don't let us write totally invalid offsets to the indexes.
1427+
throw new InvalidDataException("Cannot write invalid data offset to file.");
1428+
}
1429+
14241430
uint uOffset = (uint)(dataOffset / 8);
14251431
await _semaphoreSlim.WaitAsync();
14261432
try
@@ -1751,6 +1757,12 @@ public async Task<bool> AddFileDescriptor(string fullPath, long dataOffset, XivD
17511757
/// <returns></returns>
17521758
public async Task<int> UpdateDataOffset(long offset, string fullPath, bool updateCache = true)
17531759
{
1760+
1761+
if(offset <= 0)
1762+
{
1763+
throw new InvalidDataException("Cannot write invalid data offset to index files.");
1764+
}
1765+
17541766
var oldOffset = 0;
17551767

17561768
await _semaphoreSlim.WaitAsync();

0 commit comments

Comments
 (0)