Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ check_PROGRAMS = \
test_ppd_filter \
test_ppd_generator \
test_ppd_load_profile \
test_ppd_thread
test_ppd_thread \
test_ppd_raster \
test_ppd_rastertops
TESTS = \
testppd \
test_ppd_localize \
Expand All @@ -83,7 +85,9 @@ TESTS = \
test_ppd_filter \
test_ppd_generator \
test_ppd_load_profile \
test_ppd_thread
test_ppd_thread \
test_ppd_raster \
test_ppd_rastertops

libppd_la_SOURCES = \
ppd/ppd-attr.c \
Expand Down Expand Up @@ -278,6 +282,26 @@ test_ppd_thread_CFLAGS = \
-pthread \
$(CUPS_CFLAGS)

test_ppd_raster_SOURCES = ppd/test_ppd_raster.c
test_ppd_raster_LDADD = \
libppd.la \
$(CUPS_LIBS)
test_ppd_raster_CFLAGS = \
-I$(srcdir)/ppd/ \
$(CUPS_CFLAGS)

test_ppd_rastertops_SOURCES = ppd/test_ppd_rastertops.c
test_ppd_rastertops_LDADD = \
libppd.la \
$(CUPS_LIBS) \
$(LIBCUPSFILTERS_LIBS) \
$(ZLIB_LIBS)
test_ppd_rastertops_CFLAGS = \
-I$(srcdir)/ppd/ \
$(CUPS_CFLAGS) \
$(LIBCUPSFILTERS_CFLAGS) \
$(ZLIB_CFLAGS)

EXTRA_DIST += \
$(pkgppdinclude_DATA) \
$(pkgppddefs_DATA) \
Expand Down
13 changes: 7 additions & 6 deletions ppd/ppd-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -2388,7 +2388,7 @@ ppdCacheAssignPresets(ppd_file_t *ppd,
long total_image_data;
} choice_properties_t;
int i, j, k, l;
unsigned int m;
unsigned long long m;
int pass;
ppd_group_t *group;
ppd_option_t *option;
Expand Down Expand Up @@ -2896,9 +2896,10 @@ ppdCacheAssignPresets(ppd_file_t *ppd,
if (properties->res_x != 0 && properties->res_y != 0)
{
// Choice suggests to set the resolution
// Raising resolution compared to default?
m = (properties->res_x * properties->res_y) /
(base_res_x * base_res_y);
// Raising resolution compared to default? The pixel counts are
// 64-bit, as a 32-bit product of two resolutions can wrap to 0.
m = ((unsigned long long)properties->res_x * properties->res_y) /
((unsigned long long)base_res_x * base_res_y);
// No or small change -> Normal quality
if (m == 1)
properties->sets_normal += res_factor * 4;
Expand All @@ -2914,8 +2915,8 @@ ppdCacheAssignPresets(ppd_file_t *ppd,
else if (m < 1)
{
// Reducing resolution compared to default?
m = (base_res_x * base_res_y) /
(properties->res_x * properties->res_y);
m = ((unsigned long long)base_res_x * base_res_y) /
((unsigned long long)properties->res_x * properties->res_y);
// No or small change -> Normal quality
if (m == 1)
properties->sets_normal += res_factor * 1;
Expand Down
108 changes: 76 additions & 32 deletions ppd/raster-interpret.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <ppd/debug-internal.h>
#include <ppd/libcups2-private.h>
#include <math.h>
#include <limits.h>


//
Expand Down Expand Up @@ -87,6 +88,7 @@ static _ppd_ps_obj_t *ppd_scan_ps(_ppd_ps_stack_t *st, char **ptr);
static int ppd_setpagedevice(_ppd_ps_stack_t *st,
cups_page_header_t *h,
int *preferred_bits);
static unsigned ppd_unsigned(double v);
#ifdef DEBUG
static void ppd_DEBUG_object(const char *prefix, _ppd_ps_obj_t *obj);
static void ppd_DEBUG_stack(const char *prefix, _ppd_ps_stack_t *st);
Expand Down Expand Up @@ -140,8 +142,11 @@ ppdRasterInterpretPPD(
bottom, // Bottom position
right, // Right position
top, // Top position
width, // Width of bitmap in pixels
height, // Height of bitmap in pixels
temp1, temp2; // Temporary variables for swapping
int preferred_bits; // Preferred bits per color
unsigned long long bpl; // Bytes per line


//
Expand Down Expand Up @@ -340,22 +345,22 @@ ppdRasterInterpretPPD(
top = temp1;
}

h->PageSize[0] = (unsigned)(h->cupsPageSize[0] *
h->cupsBorderlessScalingFactor);
h->PageSize[1] = (unsigned)(h->cupsPageSize[1] *
h->cupsBorderlessScalingFactor);
h->Margins[0] = (unsigned)(left *
h->cupsBorderlessScalingFactor);
h->Margins[1] = (unsigned)(bottom *
h->cupsBorderlessScalingFactor);
h->ImagingBoundingBox[0] = (unsigned)(left *
h->cupsBorderlessScalingFactor);
h->ImagingBoundingBox[1] = (unsigned)(bottom *
h->cupsBorderlessScalingFactor);
h->ImagingBoundingBox[2] = (unsigned)(right *
h->cupsBorderlessScalingFactor);
h->ImagingBoundingBox[3] = (unsigned)(top *
h->cupsBorderlessScalingFactor);
h->PageSize[0] = ppd_unsigned((double)h->cupsPageSize[0] *
h->cupsBorderlessScalingFactor);
h->PageSize[1] = ppd_unsigned((double)h->cupsPageSize[1] *
h->cupsBorderlessScalingFactor);
h->Margins[0] = ppd_unsigned((double)left *
h->cupsBorderlessScalingFactor);
h->Margins[1] = ppd_unsigned((double)bottom *
h->cupsBorderlessScalingFactor);
h->ImagingBoundingBox[0] = ppd_unsigned((double)left *
h->cupsBorderlessScalingFactor);
h->ImagingBoundingBox[1] = ppd_unsigned((double)bottom *
h->cupsBorderlessScalingFactor);
h->ImagingBoundingBox[2] = ppd_unsigned((double)right *
h->cupsBorderlessScalingFactor);
h->ImagingBoundingBox[3] = ppd_unsigned((double)top *
h->cupsBorderlessScalingFactor);
h->cupsImagingBBox[0] = left;
h->cupsImagingBBox[1] = bottom;
h->cupsImagingBBox[2] = right;
Expand Down Expand Up @@ -391,10 +396,17 @@ ppdRasterInterpretPPD(
// Compute the bitmap parameters...
//

h->cupsWidth = (unsigned)((right - left) * h->cupsBorderlessScalingFactor *
h->HWResolution[0] / 72.0f + 0.5f);
h->cupsHeight = (unsigned)((top - bottom) * h->cupsBorderlessScalingFactor *
h->HWResolution[1] / 72.0f + 0.5f);
width = (right - left) * h->cupsBorderlessScalingFactor *
h->HWResolution[0] / 72.0f + 0.5f;
height = (top - bottom) * h->cupsBorderlessScalingFactor *
h->HWResolution[1] / 72.0f + 0.5f;

if (!(width >= 0.0f && width < 4294967296.0f) ||
!(height >= 0.0f && height < 4294967296.0f))
{
_ppdRasterAddError("Page header uses unsupported values.\n");
return (-1);
}

switch (h->cupsColorSpace)
{
Expand Down Expand Up @@ -490,10 +502,20 @@ ppdRasterInterpretPPD(
break;
}

h->cupsBytesPerLine = (h->cupsBitsPerPixel * h->cupsWidth + 7) / 8;
bpl = ((unsigned long long)h->cupsBitsPerPixel * (unsigned)width + 7) / 8;

if (h->cupsColorOrder == CUPS_ORDER_BANDED)
h->cupsBytesPerLine *= h->cupsNumColors;
bpl *= h->cupsNumColors;

if (bpl > PPD_MAX_BYTES_PER_LINE)
{
_ppdRasterAddError("Page header uses unsupported values.\n");
return (-1);
}

h->cupsWidth = (unsigned)width;
h->cupsHeight = (unsigned)height;
h->cupsBytesPerLine = (unsigned)bpl;

return (status);
}
Expand Down Expand Up @@ -1097,25 +1119,32 @@ static _ppd_ps_obj_t * // O - New object
ppd_push_stack(_ppd_ps_stack_t *st, // I - Stack
_ppd_ps_obj_t *obj) // I - Object
{
_ppd_ps_obj_t *temp; // New object
_ppd_ps_obj_t *temp, // New object
value; // Copy of the object, which may be on the stack


//
// Copy the object first: obj may point into st->objs (copy, index), which
// the realloc below can move...
//

memcpy(&value, obj, sizeof(value));

if (st->num_objs >= st->alloc_objs)
{
st->alloc_objs += 32;

if ((temp = realloc(st->objs, (size_t)st->alloc_objs *
if ((temp = realloc(st->objs, (size_t)(st->alloc_objs + 32) *
sizeof(_ppd_ps_obj_t))) == NULL)
return (NULL);

st->objs = temp;
st->objs = temp;
st->alloc_objs += 32;
memset(temp + st->num_objs, 0, 32 * sizeof(_ppd_ps_obj_t));
}

temp = st->objs + st->num_objs;
st->num_objs ++;

memcpy(temp, obj, sizeof(_ppd_ps_obj_t));
memcpy(temp, &value, sizeof(_ppd_ps_obj_t));

return (temp);
}
Expand Down Expand Up @@ -1663,8 +1692,8 @@ ppd_setpagedevice(
if (obj[1].type == PPD_PS_NUMBER && obj[2].type == PPD_PS_NUMBER &&
obj[3].type == PPD_PS_END_ARRAY)
{
h->HWResolution[0] = (unsigned)obj[1].value.number;
h->HWResolution[1] = (unsigned)obj[2].value.number;
h->HWResolution[0] = ppd_unsigned(obj[1].value.number);
h->HWResolution[1] = ppd_unsigned(obj[2].value.number);
obj += 3;
}
else
Expand Down Expand Up @@ -1711,8 +1740,8 @@ ppd_setpagedevice(
h->cupsPageSize[0] = (float)obj[1].value.number;
h->cupsPageSize[1] = (float)obj[2].value.number;

h->PageSize[0] = (unsigned)obj[1].value.number;
h->PageSize[1] = (unsigned)obj[2].value.number;
h->PageSize[0] = ppd_unsigned(obj[1].value.number);
h->PageSize[1] = ppd_unsigned(obj[2].value.number);

obj += 3;
}
Expand Down Expand Up @@ -1795,6 +1824,21 @@ ppd_setpagedevice(
}


//
// 'ppd_unsigned()' - Convert a number to an unsigned integer, 0 when out of
// range.
//

static unsigned // O - Unsigned value or 0
ppd_unsigned(double v) // I - Number to convert
{
if (v >= 0.0 && v <= (double)UINT_MAX)
return ((unsigned)v);
else
return (0);
}


#ifdef DEBUG
//
// 'ppd_DEBUG_object()' - Print an object's value...
Expand Down
7 changes: 7 additions & 0 deletions ppd/raster-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
# include <fcntl.h>
# endif // _WIN32


//
// Longest raster line, the same limit libcups applies to raster streams...
//

# define PPD_MAX_BYTES_PER_LINE (16 * 1024 * 1024)

# ifdef __cplusplus
extern "C" {
# endif // __cplusplus
Expand Down
Loading
Loading