Skip to content
Permalink
Browse files Browse the repository at this point in the history
Merge pull request #755 from libgd/bug/750
Partial fix for #750, BMP and WebP. Gif's usage of PutBuf needs too much refactoring for the actual gain here."
  • Loading branch information
pierrejoye committed Sep 8, 2021
2 parents 16ebd80 + 75fecef commit 6f51368
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/gd_bmp.c
Expand Up @@ -30,6 +30,7 @@
#include <stdlib.h>
#include "gd.h"
#include "gdhelpers.h"
#include "gd_errors.h"
#include "bmp.h"

static int compress_row(unsigned char *uncompressed_row, int length);
Expand Down Expand Up @@ -266,7 +267,11 @@ static int _gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression)
bitmap_size += compressed_size;


gdPutBuf(uncompressed_row, compressed_size, out);
if (gdPutBuf(uncompressed_row, compressed_size, out) != compressed_size){
gd_error("gd-bmp write error\n");
error = 1;
break;
}
gdPutC(BMP_RLE_COMMAND, out);
gdPutC(BMP_RLE_ENDOFLINE, out);
bitmap_size += 2;
Expand Down Expand Up @@ -325,7 +330,10 @@ static int _gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression)
if (buffer_size == 0) {
break;
}
gdPutBuf(copy_buffer , buffer_size, out_original);
if (gdPutBuf(copy_buffer , buffer_size, out_original) != buffer_size) {
gd_error("gd-bmp write error\n");
error = 1;
}
}
gdFree(copy_buffer);

Expand All @@ -335,7 +343,7 @@ static int _gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression)
out_original = NULL;
}

ret = 0;
ret = error;
cleanup:
if (tmpfile_for_compression) {
#ifdef _WIN32
Expand Down
7 changes: 6 additions & 1 deletion src/gd_webp.c
Expand Up @@ -227,8 +227,13 @@ static int _gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quality)
ret = 1;
goto freeargb;
}
gdPutBuf(out, out_size, outfile);

int res = gdPutBuf(out, out_size, outfile);
free(out);
if (res != out_size) {
gd_error("gd-webp write error\n");
ret = 1;
}

freeargb:
gdFree(argb);
Expand Down

0 comments on commit 6f51368

Please sign in to comment.