Fix M_SaveBitmap stream buffer size

- credits to dpJudas for the solution
This commit is contained in:
RaveYard 2024-12-05 00:45:02 +01:00 committed by Rachael Alexanderson
parent fc3a2e2ad1
commit 3e10e3f551
No known key found for this signature in database
GPG key ID: 26A8ACCE97115EE0

View file

@ -54,7 +54,7 @@
// MACROS ------------------------------------------------------------------
// The maximum size of an IDAT chunk ZDoom will write. This is also the
// size of the compression buffer it allocates on the stack.
// size of the compression buffer it allocates on the heap.
#define PNG_WRITE_SIZE 32768
// Set this to 1 to use a simple heuristic to select the filter to apply
@ -926,8 +926,7 @@ bool M_SaveBitmap(const uint8_t *from, ESSType color_type, int width, int height
temprow[i] = &temprow_storage[temprow_size * i];
}
TArray<Byte> array(PNG_WRITE_SIZE, true);
auto buffer = array.data();
TArray<Byte> buffer(PNG_WRITE_SIZE, true);
z_stream stream;
int err;
int y;
@ -944,8 +943,8 @@ bool M_SaveBitmap(const uint8_t *from, ESSType color_type, int width, int height
}
y = height;
stream.next_out = buffer;
stream.avail_out = sizeof(buffer);
stream.next_out = buffer.data();
stream.avail_out = buffer.size();
temprow[0][0] = 0;
#if USE_FILTER_HEURISTIC
@ -1007,12 +1006,12 @@ bool M_SaveBitmap(const uint8_t *from, ESSType color_type, int width, int height
}
while (stream.avail_out == 0)
{
if (!WriteIDAT (file, buffer, sizeof(buffer)))
if (!WriteIDAT (file, buffer.data(), buffer.size()))
{
return false;
}
stream.next_out = buffer;
stream.avail_out = sizeof(buffer);
stream.next_out = buffer.data();
stream.avail_out = buffer.size();
if (stream.avail_in != 0)
{
err = deflate (&stream, (y == 0) ? Z_FINISH : 0);
@ -1033,12 +1032,12 @@ bool M_SaveBitmap(const uint8_t *from, ESSType color_type, int width, int height
}
if (stream.avail_out == 0)
{
if (!WriteIDAT (file, buffer, sizeof(buffer)))
if (!WriteIDAT (file, buffer.data(), buffer.size()))
{
return false;
}
stream.next_out = buffer;
stream.avail_out = sizeof(buffer);
stream.next_out = buffer.data();
stream.avail_out = buffer.size();
}
}
@ -1048,7 +1047,7 @@ bool M_SaveBitmap(const uint8_t *from, ESSType color_type, int width, int height
{
return false;
}
return WriteIDAT (file, buffer, sizeof(buffer)-stream.avail_out);
return WriteIDAT (file, buffer.data(), buffer.size() - stream.avail_out);
}
//==========================================================================