fix: Fixes BitArray serialization (#1027)

Fixes bit array serialization. This may cause objects that were serialized by bit array to fail to deserialize. I am sorry, please accept my condolences. It is probably easiest to just delete those objects. If it becomes a major problem, contact me and I'll help with a hacky per-case solution.
This commit is contained in:
Kamron Batman 2022-05-18 17:25:03 -07:00 committed by GitHub
parent 6ea5508f5f
commit 6b3617b08f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 207 additions and 167 deletions

View file

@ -159,13 +159,15 @@ namespace Server
public BitArray ReadBitArray()
{
var length = ((IGenericReader)this).ReadEncodedInt();
var bitLength = ((IGenericReader)this).ReadEncodedInt();
var length = BitArray.GetByteArrayLengthFromBitLength(bitLength);
if (length > _buffer.Length - _position)
{
throw new OutOfMemoryException();
}
var bitArray = new BitArray(_buffer.AsSpan(_position, length));
var bitArray = new BitArray(_buffer.AsSpan(_position, length), bitLength);
_position += length;
return bitArray;
}

View file

@ -138,9 +138,9 @@ namespace Server
public void Write(BitArray bitArray)
{
var byteLength = BitArray.GetByteArrayLengthFromBitLength(bitArray.Length);
FlushIfNeeded(byteLength + 4);
((IGenericWriter)this).WriteEncodedInt(byteLength);
((IGenericWriter)this).WriteEncodedInt(bitArray.Length);
FlushIfNeeded(byteLength);
bitArray.CopyTo(_buffer.AsSpan((int)Index, byteLength));
Index += byteLength;
}