]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Fix a bug in cupsRasterWritePixels (STR #4650)
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Wed, 24 Jun 2015 15:55:05 +0000 (15:55 +0000)
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Wed, 24 Jun 2015 15:55:05 +0000 (15:55 +0000)
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

CHANGES-2.0.txt
filter/error.c
filter/raster.c

index 81c8dcf54fddf2d637cbc63526b65d9f3771588b..464523702c5437b354261d8f611b176e99411a30 100644 (file)
@@ -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
index 8fca072caa967d421ff25da917c6b91af8636285..39cd10391ab729320673c5104f58868260e563ce 100644 (file)
@@ -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))
index ff729a956b3ab70f2885224c037cadb485a74cee..ec3033899ce9acd4228d04eef57a11d311321f99 100644 (file)
@@ -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);
 }