From: msweet Date: Wed, 24 Jun 2015 15:55:05 +0000 (+0000) Subject: Fix a bug in cupsRasterWritePixels (STR #4650) X-Git-Tag: v2.2b1~250 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5425f93fadda948ec9e7b7652862ad98755e9ce;p=thirdparty%2Fcups.git Fix a bug in cupsRasterWritePixels (STR #4650) The return value should be the number of uncompressed bytes written, not the number of compressed bytes. git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@12747 a1ca3aef-8c08-0410-bb20-df032aa958be --- diff --git a/CHANGES-2.0.txt b/CHANGES-2.0.txt index 81c8dcf54f..464523702c 100644 --- a/CHANGES-2.0.txt +++ b/CHANGES-2.0.txt @@ -1,6 +1,11 @@ CHANGES-2.0.txt --------------- +CHANGES IN CUPS V2.0.4 + + - Fixed a bug in cupsRasterWritePixels (STR #4650) + + CHANGES IN CUPS V2.0.3 - Security: Fixed CERT VU #810572 exploiting the dynamic linker diff --git a/filter/error.c b/filter/error.c index 8fca072caa..39cd10391a 100644 --- a/filter/error.c +++ b/filter/error.c @@ -56,6 +56,8 @@ _cupsRasterAddError(const char *f, /* I - Printf-style error message */ ssize_t bytes; /* Bytes in message string */ + DEBUG_printf(("_cupsRasterAddError(f=\"%s\", ...)", f)); + va_start(ap, f); bytes = vsnprintf(s, sizeof(s), f, ap); va_end(ap); @@ -63,6 +65,8 @@ _cupsRasterAddError(const char *f, /* I - Printf-style error message */ if (bytes <= 0) return; + DEBUG_printf(("1_cupsRasterAddError: %s", s)); + bytes ++; if ((size_t)bytes >= sizeof(s)) diff --git a/filter/raster.c b/filter/raster.c index ff729a956b..ec3033899c 100644 --- a/filter/raster.c +++ b/filter/raster.c @@ -826,10 +826,15 @@ cupsRasterWritePixels(cups_raster_t *r, /* I - Raster stream */ * Write the byte-swapped buffer... */ - return ((unsigned)cups_raster_io(r, r->buffer, len)); + bytes = cups_raster_io(r, r->buffer, len); } else - return ((unsigned)cups_raster_io(r, p, len)); + bytes = cups_raster_io(r, p, len); + + if (bytes < len) + return (0); + else + return (len); } /* @@ -853,7 +858,7 @@ cupsRasterWritePixels(cups_raster_t *r, /* I - Raster stream */ if (memcmp(p, r->pcurrent, (size_t)bytes)) { - if (!cups_raster_write(r, r->pixels)) + if (cups_raster_write(r, r->pixels) <= 0) return (0); r->count = 0; @@ -882,10 +887,15 @@ cupsRasterWritePixels(cups_raster_t *r, /* I - Raster stream */ r->remaining --; if (r->remaining == 0) - return ((unsigned)cups_raster_write(r, r->pixels)); + { + if (cups_raster_write(r, r->pixels) <= 0) + return (0); + else + return (len); + } else if (r->count == 256) { - if (cups_raster_write(r, r->pixels) == 0) + if (cups_raster_write(r, r->pixels) <= 0) return (0); r->count = 0; @@ -922,7 +932,10 @@ cupsRasterWritePixels(cups_raster_t *r, /* I - Raster stream */ r->remaining --; if (r->remaining == 0) - return ((unsigned)cups_raster_write(r, r->pixels)); + { + if (cups_raster_write(r, r->pixels) <= 0) + return (0); + } } } } @@ -1029,18 +1042,25 @@ cups_raster_io(cups_raster_t *r, /* I - Raster stream */ { count = (*r->iocb)(r->ctx, buf, bytes - (size_t)total); - DEBUG_printf(("6cups_raster_io: count=%d, total=%d", (int)count, - (int)total)); + DEBUG_printf(("6cups_raster_io: count=%d, total=%d", (int)count, (int)total)); if (count == 0) + { + DEBUG_puts("6cups_raster_io: Returning 0."); return (0); + } else if (count < 0) + { + DEBUG_puts("6cups_raster_io: Returning -1 on error."); return (-1); + } #ifdef DEBUG r->iocount += (size_t)count; #endif /* DEBUG */ } + DEBUG_printf(("6cups_raster_io: Returning " CUPS_LLFMT ".", CUPS_LLCAST total)); + return (total); } @@ -1346,8 +1366,8 @@ cups_raster_write( */ count = r->header.cupsBytesPerLine * 2; - if (count < 3) - count = 3; + if (count < 65536) + count = 65536; if ((size_t)count > r->bufsize) { @@ -1357,7 +1377,10 @@ cups_raster_write( wptr = malloc(count); if (!wptr) + { + DEBUG_printf(("4cups_raster_write: Unable to allocate " CUPS_LLFMT " bytes for raster buffer: %s", CUPS_LLCAST count, strerror(errno))); return (-1); + } r->buffer = wptr; r->bufsize = count; @@ -1430,6 +1453,8 @@ cups_raster_write( } } + DEBUG_printf(("4cups_raster_write: Writing " CUPS_LLFMT " bytes.", CUPS_LLCAST (wptr - r->buffer))); + return (cups_raster_io(r, r->buffer, (size_t)(wptr - r->buffer))); } @@ -1511,7 +1536,10 @@ cups_write_fd(void *ctx, /* I - File descriptor pointer */ while ((count = write(fd, buf, bytes)) < 0) #endif /* WIN32 */ if (errno != EINTR && errno != EAGAIN) + { + DEBUG_printf(("4cups_write_fd: %s", strerror(errno))); return (-1); + } return (count); }