Browse Source

Out of range fix

pull/2481/head
Ynse Hoornenborg 3 years ago
parent
commit
7e4825332b
  1. 3
      src/ImageSharp/Formats/Pbm/BinaryDecoder.cs
  2. 3
      src/ImageSharp/Formats/Pbm/BinaryEncoder.cs

3
src/ImageSharp/Formats/Pbm/BinaryDecoder.cs

@ -161,7 +161,8 @@ internal class BinaryDecoder
for (int x = 0; x < width;)
{
int raw = stream.ReadByte();
for (int bit = 0; bit < 8; bit++)
int stopBit = Math.Min(8, width - x);
for (int bit = 0; bit < stopBit; bit++)
{
bool bitValue = (raw & (0x80 >> bit)) != 0;
rowSpan[x] = bitValue ? black : white;

3
src/ImageSharp/Formats/Pbm/BinaryEncoder.cs

@ -192,7 +192,8 @@ internal class BinaryEncoder
for (int x = 0; x < width;)
{
int value = previousValue;
for (int i = 0; i < 8; i++)
int stopBit = Math.Min(8, width - x);
for (int i = 0; i < stopBit; i++)
{
if (rowSpan[x].PackedValue < 128)
{

Loading…
Cancel
Save