Quantcast
Channel: NVorbis
Viewing all articles
Browse latest Browse all 299

Closed Issue: Crash in DataPcket.cs [21]

$
0
0
I am getting exceptions on certain ogg files in the TryPeekBits method in DataPcket.cs. I have patched it to look like this with no detectable difference in how it plays my ogg files (no more ArgumentOutOfRangeException, it just returns zeros):

/// <summary>
```
/// Attempts to read the specified number of bits from the packet, but may return fewer. Does not advance the position counter.
/// </summary>
/// <param name="count">The number of bits to attempt to read.</param>
/// <param name="bitsRead">The number of bits actually read.</param>
/// <returns>The value of the bits read.</returns>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> is not between 1 and 64.</exception>
public ulong TryPeekBits(int count, out int bitsRead)
{
ulong value = 0;
int bitShift = 0;

if (count <= 0 || count > 64) { bitsRead = 0; return 0; }// throw new ArgumentOutOfRangeException("count");

if (count + _bitCount > 64)
{
bitShift = 8;
count -= 8;
}

while (_bitCount < count)
{
var val = ReadNextByte();
if (val == -1)
{
count = _bitCount;
bitShift = 0;
break;
}
_bitBucket = (ulong)(val & 0xFF) << _bitCount | _bitBucket;
_bitCount += 8;
}

value = _bitBucket;

if (count < 64)
{
value &= (1UL << count) - 1;
}

if (bitShift > 0)
{
value |= PeekBits(bitShift) << (count - bitShift);
}

bitsRead = count;
return value;
}
```


Comments: DataPacket now supports 0 bit reads

Viewing all articles
Browse latest Browse all 299

Trending Articles