Skip to content
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

cupsRasterWritePixels incorrectly returns the size of compressed data #4650

Closed
michaelrsweet opened this issue Jun 24, 2015 · 2 comments
Closed
Milestone

Comments

@michaelrsweet
Copy link
Collaborator

Version: 2.0-current
CUPS.org User: mike

cupsRasterWritePixels incorrectly returns the number of compressed bytes written - instead it should be returning the number of uncompressed bytes.

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: mike

Fixed in Subversion repository.

@michaelrsweet
Copy link
Collaborator Author

"str4650.patch":

Index: filter/error.c

--- filter/error.c (revision 12746)
+++ filter/error.c (working copy)
@@ -56,6 +56,8 @@
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 @@
if (bytes <= 0)
return;

  • DEBUG_printf(("1_cupsRasterAddError: %s", s));

bytes ++;

if ((size_t)bytes >= sizeof(s))

Index: filter/raster.c

--- filter/raster.c (revision 12746)
+++ filter/raster.c (working copy)
@@ -826,10 +826,15 @@

  • 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 @@

    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 @@
    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 @@
    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 @@
    {
    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 @@
*/

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 @@
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 @@
}
}

  • 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 @@
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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant