Skip to content

Port fix for libgd bug 447 #17320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions ext/gd/libgd/gd_bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ static int bmp_read_4bit(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, bmp
static int bmp_read_8bit(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, bmp_hdr_t *header);
static int bmp_read_rle(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info);

static int _gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression);

#define BMP_DEBUG(s)

static int gdBMPPutWord(gdIOCtx *out, int w)
Expand Down Expand Up @@ -68,8 +70,10 @@ void * gdImageBmpPtr(gdImagePtr im, int *size, int compression)
void *rv;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I guess you can initialise it here saving 2 lines but that s nothing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but I like to stay as close to upstream as possible (I still haven't completely lost hope that at some point in time we can unbundle libgd). And there we have https://github.com/libgd/libgd/blob/77adfd27f776352e8095d98ef4902c28975d19af/src/gd_bmp.c#L88-L99

gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
if (out == NULL) return NULL;
gdImageBmpCtx(im, out, compression);
rv = gdDPExtractData(out, size);
if (!_gdImageBmpCtx(im, out, compression))
rv = gdDPExtractData(out, size);
else
rv = NULL;
out->gd_free(out);
return rv;
}
Expand All @@ -90,12 +94,17 @@ void gdImageBmp(gdImagePtr im, FILE *outFile, int compression)
*/
void gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression)
{
_gdImageBmpCtx(im, out, compression);
}

static int _gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression){
int bitmap_size = 0, info_size, total_size, padding;
int i, row, xpos, pixel;
int error = 0;
unsigned char *uncompressed_row = NULL, *uncompressed_row_start = NULL;
FILE *tmpfile_for_compression = NULL;
gdIOCtxPtr out_original = NULL;
int ret = 1;

/* No compression if its true colour or we don't support seek */
if (im->trueColor) {
Expand Down Expand Up @@ -273,6 +282,7 @@ void gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression)
out_original = NULL;
}

ret = 0;
cleanup:
if (tmpfile_for_compression) {
#ifdef _WIN32
Expand All @@ -286,7 +296,7 @@ void gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression)
if (out_original) {
out_original->gd_free(out_original);
}
return;
return ret;
}

static int compress_row(unsigned char *row, int length)
Expand Down
Loading