X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=pdf%2Fxpdf%2FGfxState.cc;h=92e5ebb1d7bb2817af9663f12f936e576fec0c18;hb=6d7f9e7cf7678b48828be0722ae2e998ce85b7a7;hp=d20293974753b9a12294dea87b928379f91082c7;hpb=ad63666daeeda50acc7630132d61fe044634fddd;p=evince.git diff --git a/pdf/xpdf/GfxState.cc b/pdf/xpdf/GfxState.cc index d2029397..92e5ebb1 100644 --- a/pdf/xpdf/GfxState.cc +++ b/pdf/xpdf/GfxState.cc @@ -714,6 +714,11 @@ GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr) { } nCompsA = obj2.getInt(); obj2.free(); + if (nCompsA > gfxColorMaxComps) { + error(-1, "ICCBased color space with too many (%d > %d) components", + nCompsA, gfxColorMaxComps); + nCompsA = gfxColorMaxComps; + } if (dict->lookup("Alternate", &obj2)->isNull() || !(altA = GfxColorSpace::parse(&obj2))) { switch (nCompsA) { @@ -766,12 +771,18 @@ void GfxICCBasedColorSpace::getCMYK(GfxColor *color, GfxCMYK *cmyk) { void GfxICCBasedColorSpace::getDefaultRanges(double *decodeLow, double *decodeRange, int maxImgPixel) { + alt->getDefaultRanges(decodeLow, decodeRange, maxImgPixel); + +#if 0 + // this is nominally correct, but some PDF files don't set the + // correct ranges in the ICCBased dict int i; for (i = 0; i < nComps; ++i) { decodeLow[i] = rangeMin[i]; decodeRange[i] = rangeMax[i] - rangeMin[i]; } +#endif } //------------------------------------------------------------------------ @@ -1053,6 +1064,11 @@ GfxColorSpace *GfxDeviceNColorSpace::parse(Array *arr) { goto err2; } nCompsA = obj1.arrayGetLength(); + if (nCompsA > gfxColorMaxComps) { + error(-1, "DeviceN color space with too many (%d > %d) components", + nCompsA, gfxColorMaxComps); + nCompsA = gfxColorMaxComps; + } for (i = 0; i < nCompsA; ++i) { if (!obj1.arrayGet(i, &obj2)->isName()) { error(-1, "Bad DeviceN color space (names)"); @@ -2030,13 +2046,18 @@ GfxImageColorMap::GfxImageColorMap(int bitsA, Object *decode, colorSpace2 = indexedCS->getBase(); indexHigh = indexedCS->getIndexHigh(); nComps2 = colorSpace2->getNComps(); - lookup = (double *)gmalloc((indexHigh + 1) * nComps2 * sizeof(double)); + lookup = (double *)gmalloc((maxPixel + 1) * nComps2 * sizeof(double)); lookup2 = indexedCS->getLookup(); colorSpace2->getDefaultRanges(x, y, indexHigh); - for (i = 0; i <= indexHigh; ++i) { + for (i = 0; i <= maxPixel; ++i) { j = (int)(decodeLow[0] + (i * decodeRange[0]) / maxPixel + 0.5); + if (j < 0) { + j = 0; + } else if (j > indexHigh) { + j = indexHigh; + } for (k = 0; k < nComps2; ++k) { - lookup[j*nComps2 + k] = x[k] + (lookup2[i*nComps2 + k] / 255.0) * y[k]; + lookup[i*nComps2 + k] = x[k] + (lookup2[j*nComps2 + k] / 255.0) * y[k]; } } } else if (colorSpace->getMode() == csSeparation) { @@ -2079,17 +2100,15 @@ GfxImageColorMap::GfxImageColorMap(GfxImageColorMap *colorMap) { nComps2 = colorMap->nComps2; colorSpace2 = NULL; lookup = NULL; + n = 1 << bits; if (colorSpace->getMode() == csIndexed) { colorSpace2 = ((GfxIndexedColorSpace *)colorSpace)->getBase(); - n = ((GfxIndexedColorSpace *)colorSpace)->getIndexHigh(); - n = (n + 1) * nComps2 * sizeof(double); + n = n * nComps2 * sizeof(double); } else if (colorSpace->getMode() == csSeparation) { colorSpace2 = ((GfxSeparationColorSpace *)colorSpace)->getAlt(); - n = (1 << bits) - 1; - n = (n + 1) * nComps2 * sizeof(double); + n = n * nComps2 * sizeof(double); } else { - n = (1 << bits) - 1; - n = (n + 1) * nComps * sizeof(double); + n = n * nComps * sizeof(double); } lookup = (double *)gmalloc(n); memcpy(lookup, colorMap->lookup, n); @@ -2497,6 +2516,11 @@ GfxState::GfxState(GfxState *state) { saved = NULL; } +void GfxState::setPath(GfxPath *pathA) { + delete path; + path = pathA; +} + void GfxState::getUserClipBBox(double *xMin, double *yMin, double *xMax, double *yMax) { double ictm[6];