mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-11-15 17:02:03 +00:00
Fix PPMd properties state after rejected allocator changes
This commit is contained in:
@@ -55,13 +55,14 @@ public class PpmdProperties
|
||||
get => _allocatorSize;
|
||||
set
|
||||
{
|
||||
_allocatorSize = value;
|
||||
if (Version == PpmdVersion.I1)
|
||||
{
|
||||
_allocator ??= new Allocator();
|
||||
|
||||
_allocator.Start(_allocatorSize);
|
||||
_allocator.Start(value);
|
||||
}
|
||||
// Keep the serialized properties in sync with the allocator if Start rejects the size.
|
||||
_allocatorSize = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -154,6 +154,23 @@ public class DictionarySizeLimitTests : TestBase
|
||||
Assert.Throws<InvalidFormatException>(() => new PpmdProperties(256 << 20, 6));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ppmd_Properties_Preserve_Size_After_Rejected_Change()
|
||||
{
|
||||
using var limits = new DictionarySizeLimitScope();
|
||||
DictionarySizeLimits.Ppmd = 2 << 20;
|
||||
var properties = new PpmdProperties(1 << 20, 6);
|
||||
var originalHeader = properties.Properties;
|
||||
|
||||
Assert.Throws<InvalidFormatException>(() => properties.AllocatorSize = 3 << 20);
|
||||
Assert.Equal(1 << 20, properties.AllocatorSize);
|
||||
Assert.Equal(originalHeader, properties.Properties);
|
||||
|
||||
properties.AllocatorSize = 2 << 20;
|
||||
Assert.Equal(2 << 20, properties.AllocatorSize);
|
||||
Assert.Equal(2 << 20, new PpmdProperties(properties.Properties).AllocatorSize);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
|
||||
Reference in New Issue
Block a user