[prev in list] [next in list] [prev in thread] [next in thread]
List: cups-bugs
Subject: Re: [cups.bugs] [HIGH] STR #3812: Failure to read last page of
From: Michael Sweet <msweet () apple ! com>
Date: 2011-03-11 23:54:06
Message-ID: 20110311235406.5386D3C68413 () dns ! easysw ! com
[Download RAW message or body]
DO NOT REPLY TO THIS MESSAGE. INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.
[STR Closed w/Resolution]
Fixed in Subversion repository.
Link: http://www.cups.org/str.php?L3812
Version: 1.4-current
Fix Version: 1.5-current (r9597)
["str3812.patch" (text/plain)]
Index: filter/testraster.c
===================================================================
--- filter/testraster.c (revision 9595)
+++ filter/testraster.c (working copy)
@@ -19,6 +19,7 @@
* main() - Test the raster functions.
* do_ppd_tests() - Test the default option commands in a PPD file.
* do_ps_tests() - Test standard PostScript commands.
+ * do_ras_file() - Test reading of a raster file.
* do_raster_tests() - Test reading and writing of raster data.
* print_changes() - Print differences in the page header.
*/
@@ -28,6 +29,12 @@
*/
#include "image-private.h"
+#ifdef WIN32
+# include <io.h>
+#else
+# include <unistd.h>
+# include <fcntl.h>
+#endif /* WIN32 */
/*
@@ -193,6 +200,7 @@
static int do_ppd_tests(const char *filename, int num_options,
cups_option_t *options);
static int do_ps_tests(void);
+static int do_ras_file(const char *filename);
static int do_raster_tests(cups_mode_t mode);
static void print_changes(cups_page_header2_t *header,
cups_page_header2_t *expected);
@@ -207,6 +215,7 @@
char *argv[]) /* I - Command-line arguments */
{
int errors; /* Number of errors */
+ const char *ext; /* Filename extension */
if (argc == 1)
@@ -239,6 +248,7 @@
else
{
puts("Usage: testraster [-o name=value ...] [filename.ppd ...]");
+ puts(" testraster [filename.ras ...]");
return (1);
}
}
@@ -246,11 +256,23 @@
else
{
puts("Usage: testraster [-o name=value ...] [filename.ppd ...]");
+ puts(" testraster [filename.ras ...]");
return (1);
}
}
+ else if ((ext = strrchr(argv[i], '.')) != NULL)
+ {
+ if (!strcmp(ext, ".ppd"))
+ errors += do_ppd_tests(argv[i], num_options, options);
+ else
+ errors += do_ras_file(argv[i]);
+ }
else
- errors += do_ppd_tests(argv[i], num_options, options);
+ {
+ puts("Usage: testraster [-o name=value ...] [filename.ppd ...]");
+ puts(" testraster [filename.ras ...]");
+ return (1);
+ }
}
cupsFreeOptions(num_options, options);
@@ -352,7 +374,7 @@
}
else
puts("PASS");
-
+
fputs("_cupsRasterExecPS(\"roll\"): ", stdout);
fflush(stdout);
@@ -431,93 +453,67 @@
else
puts("PASS");
-#if 0
- fputs("_cupsRasterExecPS(\"\"): ", stdout);
- fflush(stdout);
+ return (errors);
+}
- if (_cupsRasterExecPS(&header, &preferred_bits,
- ""))
- {
- puts("FAIL (error from function)");
- errors ++;
- }
- else if (header.)
- {
- printf("FAIL ()\n");
- errors ++;
- }
- else
- puts("PASS");
- fputs("_cupsRasterExecPS(\"\"): ", stdout);
- fflush(stdout);
+/*
+ * 'do_ras_file()' - Test reading of a raster file.
+ */
- if (_cupsRasterExecPS(&header, &preferred_bits,
- ""))
- {
- puts("FAIL (error from function)");
- errors ++;
- }
- else if (header.)
- {
- printf("FAIL ()\n");
- errors ++;
- }
- else
- puts("PASS");
+static int /* O - Number of errors */
+do_ras_file(const char *filename) /* I - Filename */
+{
+ unsigned y; /* Looping vars */
+ int fd; /* File descriptor */
+ cups_raster_t *ras; /* Raster stream */
+ cups_page_header2_t header; /* Page header */
+ unsigned char *data; /* Raster data */
+ int errors = 0; /* Number of errors */
+ unsigned pages = 0; /* Number of pages */
- fputs("_cupsRasterExecPS(\"\"): ", stdout);
- fflush(stdout);
- if (_cupsRasterExecPS(&header, &preferred_bits,
- ""))
+ if ((fd = open(filename, O_RDONLY)) < 0)
{
- puts("FAIL (error from function)");
- errors ++;
+ printf("%s: %s\n", filename, strerror(errno));
+ return (1);
}
- else if (header.)
+
+ if ((ras = cupsRasterOpen(fd, CUPS_RASTER_READ)) == NULL)
{
- printf("FAIL ()\n");
- errors ++;
+ printf("%s: cupsRasterOpen failed.\n", filename);
+ close(fd);
+ return (1);
}
- else
- puts("PASS");
- fputs("_cupsRasterExecPS(\"\"): ", stdout);
- fflush(stdout);
+ printf("%s:\n", filename);
- if (_cupsRasterExecPS(&header, &preferred_bits,
- ""))
+ while (cupsRasterReadHeader2(ras, &header))
{
- puts("FAIL (error from function)");
- errors ++;
- }
- else if (header.)
- {
- printf("FAIL ()\n");
- errors ++;
- }
- else
- puts("PASS");
+ pages ++;
+ data = malloc(header.cupsBytesPerLine);
- fputs("_cupsRasterExecPS(\"\"): ", stdout);
- fflush(stdout);
+ printf(" Page %u: %ux%ux%u@%ux%udpi", pages,
+ header.cupsWidth, header.cupsHeight, header.cupsBitsPerPixel,
+ header.HWResolution[0], header.HWResolution[1]);
+ fflush(stdout);
- if (_cupsRasterExecPS(&header, &preferred_bits,
- ""))
- {
- puts("FAIL (error from function)");
- errors ++;
+ for (y = 0; y < header.cupsHeight; y ++)
+ if (cupsRasterReadPixels(ras, data, header.cupsBytesPerLine) <
+ header.cupsBytesPerLine)
+ break;
+
+ if (y < header.cupsHeight)
+ printf(" ERROR AT LINE %d\n", y);
+ else
+ putchar('\n');
+
+ free(data);
}
- else if (header.)
- {
- printf("FAIL ()\n");
- errors ++;
- }
- else
- puts("PASS");
-#endif /* 0 */
+ cupsRasterClose(ras);
+ close(fd);
+
return (errors);
}
Index: filter/raster.c
===================================================================
--- filter/raster.c (revision 9595)
+++ filter/raster.c (working copy)
@@ -84,6 +84,7 @@
* Local functions...
*/
+static int cups_raster_io(cups_raster_t *r, unsigned char *buf, int bytes);
static unsigned cups_raster_read_header(cups_raster_t *r);
static int cups_raster_read(cups_raster_t *r, unsigned char *buf,
int bytes);
@@ -189,7 +190,7 @@
* Open for read - get sync word...
*/
- if ((*r->iocb)(r->ctx, (unsigned char *)&(r->sync), sizeof(r->sync)) !=
+ if (cups_raster_io(r, (unsigned char *)&(r->sync), sizeof(r->sync)) !=
sizeof(r->sync))
{
_cupsRasterAddError("Unable to read header from raster stream: %s\n",
@@ -246,7 +247,7 @@
break;
}
- if ((*r->iocb)(r->ctx, (unsigned char *)&(r->sync), sizeof(r->sync))
+ if (cups_raster_io(r, (unsigned char *)&(r->sync), sizeof(r->sync))
< sizeof(r->sync))
{
_cupsRasterAddError("Unable to write raster stream header: %s\n",
@@ -284,7 +285,7 @@
if (!cups_raster_read_header(r))
return (0);
-
+
/*
* Copy the header to the user-supplied buffer...
*/
@@ -313,7 +314,7 @@
if (!cups_raster_read_header(r))
return (0);
-
+
/*
* Copy the header to the user-supplied buffer...
*/
@@ -357,7 +358,7 @@
r->remaining -= len / r->header.cupsBytesPerLine;
- if ((*r->iocb)(r->ctx, p, len) < (ssize_t)len)
+ if (cups_raster_io(r, p, len) < (ssize_t)len)
return (0);
/*
@@ -538,7 +539,7 @@
*
* @deprecated@
*/
-
+
unsigned /* O - 1 on success, 0 on failure */
cupsRasterWriteHeader(
cups_raster_t *r, /* I - Raster stream */
@@ -581,10 +582,10 @@
fh.cupsColorOrder = htonl(r->header.cupsColorOrder);
fh.cupsColorSpace = htonl(r->header.cupsColorSpace);
- return ((*r->iocb)(r->ctx, (unsigned char *)&fh, sizeof(fh)) == sizeof(fh));
+ return (cups_raster_io(r, (unsigned char *)&fh, sizeof(fh)) == sizeof(fh));
}
else
- return ((*r->iocb)(r->ctx, (unsigned char *)&(r->header), sizeof(r->header))
+ return (cups_raster_io(r, (unsigned char *)&(r->header), sizeof(r->header))
== sizeof(r->header));
}
@@ -597,7 +598,7 @@
*
* @since CUPS 1.2/Mac OS X 10.5@
*/
-
+
unsigned /* O - 1 on success, 0 on failure */
cupsRasterWriteHeader2(
cups_raster_t *r, /* I - Raster stream */
@@ -639,10 +640,10 @@
fh.cupsColorOrder = htonl(r->header.cupsColorOrder);
fh.cupsColorSpace = htonl(r->header.cupsColorSpace);
- return ((*r->iocb)(r->ctx, (unsigned char *)&fh, sizeof(fh)) == sizeof(fh));
+ return (cups_raster_io(r, (unsigned char *)&fh, sizeof(fh)) == sizeof(fh));
}
else
- return ((*r->iocb)(r->ctx, (unsigned char *)&(r->header), sizeof(r->header))
+ return (cups_raster_io(r, (unsigned char *)&(r->header), sizeof(r->header))
== sizeof(r->header));
}
@@ -722,10 +723,10 @@
* Write the byte-swapped buffer...
*/
- return ((*r->iocb)(r->ctx, r->buffer, len));
+ return (cups_raster_io(r, r->buffer, len));
}
else
- return ((*r->iocb)(r->ctx, p, len));
+ return (cups_raster_io(r, p, len));
}
/*
@@ -898,6 +899,37 @@
/*
+ * 'cups_raster_io()' - Read/write bytes from a context, handling interruptions.
+ */
+
+static int /* O - Bytes read or -1 */
+cups_raster_io(cups_raster_t *r, /* I - Raster stream */
+ unsigned char *buf, /* I - Buffer for read/write */
+ int bytes) /* I - Number of bytes to read/write */
+{
+ ssize_t count; /* Number of bytes read/written */
+ size_t total; /* Total bytes read/written */
+
+
+ DEBUG_printf(("4cups_raster_io(r=%p, buf=%p, bytes=%d)", r, buf, bytes));
+
+ for (total = 0; total < bytes; total += count, buf += count)
+ {
+ count = (*r->iocb)(r->ctx, buf, bytes - total);
+
+ DEBUG_printf(("5cups_raster_io: count=%d, total=%d", (int)count,
+ (int)total));
+ if (count == 0)
+ return (0);
+ else if (count < 0)
+ return (-1);
+ }
+
+ return ((int)total);
+}
+
+
+/*
* 'cups_raster_read()' - Read through the raster buffer.
*/
@@ -914,7 +946,7 @@
DEBUG_printf(("cups_raster_read(r=%p, buf=%p, bytes=%d)\n", r, buf, bytes));
if (!r->compressed)
- return ((*r->iocb)(r->ctx, buf, bytes));
+ return (cups_raster_io(r, buf, bytes));
/*
* Allocate a read buffer as needed...
@@ -1256,7 +1288,7 @@
count ++;
ptr += bpp;
}
-
+
*wptr++ = 257 - count;
count *= bpp;
@@ -1265,7 +1297,7 @@
}
}
- return ((*r->iocb)(r->ctx, r->buffer, wptr - r->buffer));
+ return (cups_raster_io(r, r->buffer, wptr - r->buffer));
}
@@ -1276,30 +1308,18 @@
static ssize_t /* O - Bytes read or -1 */
cups_read_fd(void *ctx, /* I - File descriptor as pointer */
unsigned char *buf, /* I - Buffer for read */
- size_t bytes) /* I - Number of bytes to read */
+ size_t bytes) /* I - Maximum number of bytes to read */
{
int fd = (int)((intptr_t)ctx);
/* File descriptor */
ssize_t count; /* Number of bytes read */
- size_t total; /* Total bytes read */
- for (total = 0; total < bytes; total += count, buf += count)
- {
- count = read(fd, buf, bytes - total);
+ while ((count = read(fd, buf, bytes)) < 0)
+ if (errno != EINTR && errno != EAGAIN)
+ return (-1);
- if (count == 0)
- return (0);
- else if (count < 0)
- {
- if (errno == EINTR)
- count = 0;
- else
- return (-1);
- }
- }
-
- return ((ssize_t)total);
+ return (count);
}
@@ -1341,23 +1361,13 @@
int fd = (int)((intptr_t)ctx);
/* File descriptor */
ssize_t count; /* Number of bytes written */
- size_t total; /* Total bytes written */
- for (total = 0; total < bytes; total += count, buf += count)
- {
- count = write(fd, buf, bytes - total);
+ while ((count = write(fd, buf, bytes)) < 0)
+ if (errno != EINTR && errno != EAGAIN)
+ return (-1);
- if (count < 0)
- {
- if (errno == EINTR)
- count = 0;
- else
- return (-1);
- }
- }
-
- return ((ssize_t)total);
+ return (count);
}
_______________________________________________
cups-bugs mailing list
cups-bugs@easysw.com
http://lists.easysw.com/mailman/listinfo/cups-bugs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic