Skip to content

Commit 7e48253

Browse files
committed
Out of range fix
1 parent bbc14f4 commit 7e48253

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/ImageSharp/Formats/Pbm/BinaryDecoder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ private static void ProcessBlackAndWhite<TPixel>(Configuration configuration, Bu
161161
for (int x = 0; x < width;)
162162
{
163163
int raw = stream.ReadByte();
164-
for (int bit = 0; bit < 8; bit++)
164+
int stopBit = Math.Min(8, width - x);
165+
for (int bit = 0; bit < stopBit; bit++)
165166
{
166167
bool bitValue = (raw & (0x80 >> bit)) != 0;
167168
rowSpan[x] = bitValue ? black : white;

src/ImageSharp/Formats/Pbm/BinaryEncoder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ private static void WriteBlackAndWhite<TPixel>(Configuration configuration, Stre
192192
for (int x = 0; x < width;)
193193
{
194194
int value = previousValue;
195-
for (int i = 0; i < 8; i++)
195+
int stopBit = Math.Min(8, width - x);
196+
for (int i = 0; i < stopBit; i++)
196197
{
197198
if (rowSpan[x].PackedValue < 128)
198199
{

0 commit comments

Comments
 (0)