Ignore:
Timestamp:
Feb 13, 2012, 10:07:12 PM (14 years ago)
Author:
dmik
Message:

trunk: Merged in openjdk6 b24 from branches/vendor/oracle.

Location:
trunk/openjdk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/openjdk

  • trunk/openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/unpack.cpp

    r278 r309  
    11/*
    2  * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
     2 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
    33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    44 *
     
    10891089    if (suffix == 0)  continue;  // done with empty string
    10901090    chars.malloc(size3);
     1091    CHECK;
    10911092    byte* chp = chars.ptr;
    10921093    band saved_band = cp_Utf8_big_chars;
    10931094    cp_Utf8_big_chars.readData(suffix);
     1095    CHECK;
    10941096    for (int j = 0; j < suffix; j++) {
    10951097      unsigned short ch = cp_Utf8_big_chars.getInt();
     1098      CHECK;
    10961099      chp = store_Utf8_char(chp, ch);
    10971100    }
     
    11111114  int prevlen = 0;  // previous string length (in chars)
    11121115  tmallocs.add(bigbuf.ptr);  // free after this block
     1116  CHECK;
    11131117  cp_Utf8_prefix.rewind();
    11141118  for (i = 0; i < len; i++) {
    11151119    bytes& chars = allsuffixes[i];
    11161120    int prefix = (i < PREFIX_SKIP_2)? 0: cp_Utf8_prefix.getInt();
     1121    CHECK;
    11171122    int suffix = chars.len;
    11181123    byte* fillp;
  • trunk/openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/utils.cpp

    r278 r309  
    11/*
    2  * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved.
     2 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
    33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    44 *
     
    5353    msize = sizeof(int);  // see 0xbaadf00d below
    5454  #endif
    55   void* ptr = (msize > PSIZE_MAX) ? null : malloc(msize);
     55  void* ptr = (msize > PSIZE_MAX || msize <= 0) ? null : malloc(msize);
    5656  if (ptr != null) {
    5757    memset(ptr, 0, size);
  • trunk/openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/utils.h

    r278 r309  
    11/*
    2  * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved.
     2 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
    33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    44 *
     
    3434
    3535// overflow management
    36 #define OVERFLOW ((size_t)-1)
     36#define OVERFLOW ((uint)-1)
    3737#define PSIZE_MAX (OVERFLOW/2)  /* normal size limit */
    3838
  • trunk/openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c

    r278 r309  
    4141#include <assert.h>
    4242#include <string.h>
     43#include <limits.h>
    4344
    4445
     
    19221923
    19231924    // Allocate a 1-scanline buffer
     1925    if (cinfo->num_components <= 0 ||
     1926        cinfo->image_width > (UINT_MAX / (unsigned int)cinfo->num_components))
     1927    {
     1928        RELEASE_ARRAYS(env, data, src->next_input_byte);
     1929        JNU_ThrowByName(env, "javax/imageio/IIOException",
     1930                        "Invalid number of color components");
     1931        return data->abortFlag;
     1932    }
    19241933    scanLinePtr = (JSAMPROW)malloc(cinfo->image_width*cinfo->num_components);
    19251934    if (scanLinePtr == NULL) {
  • trunk/openjdk/jdk/src/share/native/sun/font/layout/SunLayoutEngine.cpp

    r278 r309  
    187187  jchar* chars = buffer;
    188188  if (len > 256) {
    189     chars = (jchar*)malloc(len * sizeof(jchar));
     189    size_t size = len * sizeof(jchar);
     190    if (size / sizeof(jchar) != len) {
     191      return;
     192    }
     193    chars = (jchar*)malloc(size);
    190194    if (chars == 0) {
    191195      return;
  • trunk/openjdk/jdk/src/share/native/sun/java2d/loops/TransformHelper.c

    r278 r309  
    11/*
    2  * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
     2 * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
    33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    44 *
     
    7676
    7777/*
     78 * The dxydxy parameters of the inverse transform determine how
     79 * quickly we step through the source image.  For tiny scale
     80 * factors (on the order of 1E-16 or so) the stepping distances
     81 * are huge.  The image has been scaled so small that stepping
     82 * a single pixel in device space moves the sampling point by
     83 * billions (or more) pixels in the source image space.  These
     84 * huge stepping values can overflow the whole part of the longs
     85 * we use for the fixed point stepping equations and so we need
     86 * a more robust solution.  We could simply iterate over every
     87 * device pixel, use the inverse transform to transform it back
     88 * into the source image coordinate system and then test it for
     89 * being in range and sample pixel-by-pixel, but that is quite
     90 * a bit more expensive.  Fortunately, if the scale factors are
     91 * so tiny that we overflow our long values then the number of
     92 * pixels we are planning to visit should be very tiny.  The only
     93 * exception to that rule is if the scale factor along one
     94 * dimension is tiny (creating the huge stepping values), and
     95 * the scale factor along the other dimension is fairly regular
     96 * or an up-scale.  In that case we have a lot of pixels along
     97 * the direction of the larger axis to sample, but few along the
     98 * smaller axis.  Though, pessimally, with an added shear factor
     99 * such a linearly tiny image could have bounds that cover a large
     100 * number of pixels.  Such odd transformations should be very
     101 * rare and the absolute limit on calculations would involve a
     102 * single reverse transform of every pixel in the output image
     103 * which is not fast, but it should not cause an undue stall
     104 * of the rendering software.
     105 *
     106 * The specific test we will use is to calculate the inverse
     107 * transformed values of every corner of the destination bounds
     108 * (in order to be user-clip independent) and if we can
     109 * perform a fixed-point-long inverse transform of all of
     110 * those points without overflowing we will use the fast
     111 * fixed point algorithm.  Otherwise we will use the safe
     112 * per-pixel transform algorithm.
     113 * The 4 corners are 0,0, 0,dsth, dstw,0, dstw,dsth
     114 * Transformed they are:
     115 *     tx,               ty
     116 *     tx       +dxdy*H, ty       +dydy*H
     117 *     tx+dxdx*W,        ty+dydx*W
     118 *     tx+dxdx*W+dxdy*H, ty+dydx*W+dydy*H
     119 */
     120/* We reject coordinates not less than 1<<30 so that the distance between */
     121/* any 2 of them is less than 1<<31 which would overflow into the sign */
     122/* bit of a signed long value used to represent fixed point coordinates. */
     123#define TX_FIXED_UNSAFE(v)  (fabs(v) >= (1<<30))
     124static jboolean
     125checkOverflow(jint dxoff, jint dyoff,
     126              SurfaceDataBounds *pBounds,
     127              TransformInfo *pItxInfo,
     128              jdouble *retx, jdouble *rety)
     129{
     130    jdouble x, y;
     131
     132    x = dxoff+pBounds->x1+0.5; /* Center of pixel x1 */
     133    y = dyoff+pBounds->y1+0.5; /* Center of pixel y1 */
     134    Transform_transform(pItxInfo, &x, &y);
     135    *retx = x;
     136    *rety = y;
     137    if (TX_FIXED_UNSAFE(x) || TX_FIXED_UNSAFE(y)) {
     138        return JNI_TRUE;
     139    }
     140
     141    x = dxoff+pBounds->x2-0.5; /* Center of pixel x2-1 */
     142    y = dyoff+pBounds->y1+0.5; /* Center of pixel y1 */
     143    Transform_transform(pItxInfo, &x, &y);
     144    if (TX_FIXED_UNSAFE(x) || TX_FIXED_UNSAFE(y)) {
     145        return JNI_TRUE;
     146    }
     147
     148    x = dxoff+pBounds->x1+0.5; /* Center of pixel x1 */
     149    y = dyoff+pBounds->y2-0.5; /* Center of pixel y2-1 */
     150    Transform_transform(pItxInfo, &x, &y);
     151    if (TX_FIXED_UNSAFE(x) || TX_FIXED_UNSAFE(y)) {
     152        return JNI_TRUE;
     153    }
     154
     155    x = dxoff+pBounds->x2-0.5; /* Center of pixel x2-1 */
     156    y = dyoff+pBounds->y2-0.5; /* Center of pixel y2-1 */
     157    Transform_transform(pItxInfo, &x, &y);
     158    if (TX_FIXED_UNSAFE(x) || TX_FIXED_UNSAFE(y)) {
     159        return JNI_TRUE;
     160    }
     161
     162    return JNI_FALSE;
     163}
     164
     165/*
    78166 * Fill the edge buffer with pairs of coordinates representing the maximum
    79167 * left and right pixels of the destination surface that should be processed
     
    83171 * source coordinate that falls within the (0, 0, sw, sh) bounds of the
    84172 * source image should be processed.
    85  * pEdgeBuf points to an array of jints that holds MAXEDGES*2 values.
    86  * If more storage is needed, then this function allocates a new buffer.
    87  * In either case, a pointer to the buffer actually used to store the
    88  * results is returned.
    89  * The caller is responsible for freeing the buffer if the return value
    90  * is not the same as the original pEdgeBuf passed in.
     173 * pEdges points to an array of jints that holds 2 + numedges*2 values where
     174 * numedges should match (pBounds->y2 - pBounds->y1).
     175 * The first two jints in pEdges should be set to y1 and y2 and every pair
     176 * of jints after that represent the xmin,xmax of all pixels in range of
     177 * the transformed blit for the corresponding scanline.
    91178 */
    92 static jint *
    93 calculateEdges(jint *pEdgeBuf,
     179static void
     180calculateEdges(jint *pEdges,
    94181               SurfaceDataBounds *pBounds,
    95182               TransformInfo *pItxInfo,
     
    97184               juint sw, juint sh)
    98185{
    99     jint *pEdges;
    100186    jlong dxdxlong, dydxlong;
    101187    jlong dxdylong, dydylong;
     
    112198    dx2 = pBounds->x2;
    113199    dy2 = pBounds->y2;
    114     if ((dy2-dy1) > MAXEDGES) {
    115         pEdgeBuf = malloc(2 * (dy2-dy1) * sizeof (*pEdges));
    116     }
    117     pEdges = pEdgeBuf;
     200    *pEdges++ = dy1;
     201    *pEdges++ = dy2;
    118202
    119203    drowxlong = (dx2-dx1-1) * dxdxlong;
     
    156240        dy1++;
    157241    }
    158 
    159     return pEdgeBuf;
    160242}
     243
     244static void
     245Transform_SafeHelper(JNIEnv *env,
     246                     SurfaceDataOps *srcOps,
     247                     SurfaceDataOps *dstOps,
     248                     SurfaceDataRasInfo *pSrcInfo,
     249                     SurfaceDataRasInfo *pDstInfo,
     250                     NativePrimitive *pMaskBlitPrim,
     251                     CompositeInfo *pCompInfo,
     252                     TransformHelperFunc *pHelperFunc,
     253                     TransformInterpFunc *pInterpFunc,
     254                     RegionData *pClipInfo, TransformInfo *pItxInfo,
     255                     jint *pData, jint *pEdges,
     256                     jint dxoff, jint dyoff, jint sw, jint sh);
    161257
    162258/*
     
    188284    TransformHelperFunc *pHelperFunc;
    189285    TransformInterpFunc *pInterpFunc;
    190     jint edgebuf[MAXEDGES * 2];
     286    jdouble xorig, yorig;
     287    jlong numedges;
    191288    jint *pEdges;
    192     jdouble x, y;
    193     jlong xbase, ybase;
    194     jlong dxdxlong, dydxlong;
    195     jlong dxdylong, dydylong;
     289    jint edgebuf[2 + MAXEDGES * 2];
     290    union {
     291        jlong align;
     292        jint data[LINE_SIZE];
     293    } rgb;
    196294
    197295#ifdef MAKE_STUBS
     
    270368        != SD_SUCCESS)
    271369    {
     370        /* edgeArray should already contain zeros for min/maxy */
    272371        return;
    273372    }
     
    276375    {
    277376        SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);
     377        /* edgeArray should already contain zeros for min/maxy */
    278378        return;
    279379    }
    280380    Region_IntersectBounds(&clipInfo, &dstInfo.bounds);
    281381
     382    numedges = (((jlong) dstInfo.bounds.y2) - ((jlong) dstInfo.bounds.y1));
     383    if (numedges <= 0) {
     384        pEdges = NULL;
     385    } else if (!JNU_IsNull(env, edgeArray)) {
     386        /*
     387         * Ideally Java should allocate an array large enough, but if
     388         * we ever have a miscommunication about the number of edge
     389         * lines, or if the Java array calculation should overflow to
     390         * a positive number and succeed in allocating an array that
     391         * is too small, we need to verify that it can still hold the
     392         * number of integers that we plan to store to be safe.
     393         */
     394        jsize edgesize = (*env)->GetArrayLength(env, edgeArray);
     395        /* (edgesize/2 - 1) should avoid any overflow or underflow. */
     396        pEdges = (((edgesize / 2) - 1) >= numedges)
     397            ? (*env)->GetPrimitiveArrayCritical(env, edgeArray, NULL)
     398            : NULL;
     399    } else if (numedges > MAXEDGES) {
     400        /* numedges variable (jlong) can be at most ((1<<32)-1) */
     401        /* memsize can overflow a jint, but not a jlong */
     402        jlong memsize = ((numedges * 2) + 2) * sizeof(*pEdges);
     403        pEdges = (memsize == ((size_t) memsize))
     404            ? malloc((size_t) memsize)
     405            : NULL;
     406    } else {
     407        pEdges = edgebuf;
     408    }
     409    if (pEdges == NULL) {
     410        if (numedges > 0) {
     411            JNU_ThrowInternalError(env, "Unable to allocate edge list");
     412        }
     413        SurfaceData_InvokeUnlock(env, dstOps, &dstInfo);
     414        SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);
     415        /* edgeArray should already contain zeros for min/maxy */
     416        return;
     417    }
     418
    282419    Transform_GetInfo(env, itxform, &itxInfo);
    283     dxdxlong = DblToLong(itxInfo.dxdx);
    284     dydxlong = DblToLong(itxInfo.dydx);
    285     dxdylong = DblToLong(itxInfo.dxdy);
    286     dydylong = DblToLong(itxInfo.dydy);
    287     x = dxoff+dstInfo.bounds.x1+0.5; /* Center of pixel x1 */
    288     y = dyoff+dstInfo.bounds.y1+0.5; /* Center of pixel y1 */
    289     Transform_transform(&itxInfo, &x, &y);
    290     xbase = DblToLong(x);
    291     ybase = DblToLong(y);
    292 
    293     pEdges = calculateEdges(edgebuf, &dstInfo.bounds, &itxInfo,
    294                             xbase, ybase, sx2-sx1, sy2-sy1);
    295420
    296421    if (!Region_IsEmpty(&clipInfo)) {
    297422        srcOps->GetRasInfo(env, srcOps, &srcInfo);
    298423        dstOps->GetRasInfo(env, dstOps, &dstInfo);
    299         if (srcInfo.rasBase && dstInfo.rasBase) {
    300             union {
    301                 jlong align;
    302                 jint data[LINE_SIZE];
    303             } rgb;
     424        if (srcInfo.rasBase == NULL || dstInfo.rasBase == NULL) {
     425            pEdges[0] = pEdges[1] = 0;
     426        } else if (checkOverflow(dxoff, dyoff, &dstInfo.bounds,
     427                                 &itxInfo, &xorig, &yorig))
     428        {
     429            Transform_SafeHelper(env, srcOps, dstOps,
     430                                 &srcInfo, &dstInfo,
     431                                 pMaskBlitPrim, &compInfo,
     432                                 pHelperFunc, pInterpFunc,
     433                                 &clipInfo, &itxInfo, rgb.data, pEdges,
     434                                 dxoff, dyoff, sx2-sx1, sy2-sy1);
     435        } else {
    304436            SurfaceDataBounds span;
     437            jlong dxdxlong, dydxlong;
     438            jlong dxdylong, dydylong;
     439            jlong xbase, ybase;
     440
     441            dxdxlong = DblToLong(itxInfo.dxdx);
     442            dydxlong = DblToLong(itxInfo.dydx);
     443            dxdylong = DblToLong(itxInfo.dxdy);
     444            dydylong = DblToLong(itxInfo.dydy);
     445            xbase = DblToLong(xorig);
     446            ybase = DblToLong(yorig);
     447
     448            calculateEdges(pEdges, &dstInfo.bounds, &itxInfo,
     449                           xbase, ybase, sx2-sx1, sy2-sy1);
    305450
    306451            Region_StartIteration(env, &clipInfo);
     
    319464                    /* Note - process at most one scanline at a time. */
    320465
    321                     dx1 = pEdges[(dy1 - dstInfo.bounds.y1) * 2];
    322                     dx2 = pEdges[(dy1 - dstInfo.bounds.y1) * 2 + 1];
     466                    dx1 = pEdges[(dy1 - dstInfo.bounds.y1) * 2 + 2];
     467                    dx2 = pEdges[(dy1 - dstInfo.bounds.y1) * 2 + 3];
    323468                    if (dx1 < span.x1) dx1 = span.x1;
    324469                    if (dx2 > span.x2) dx2 = span.x2;
     
    377522        SurfaceData_InvokeRelease(env, dstOps, &dstInfo);
    378523        SurfaceData_InvokeRelease(env, srcOps, &srcInfo);
     524    } else {
     525        pEdges[0] = pEdges[1] = 0;
     526    }
     527    if (!JNU_IsNull(env, edgeArray)) {
     528        (*env)->ReleasePrimitiveArrayCritical(env, edgeArray, pEdges, 0);
     529    } else if (pEdges != edgebuf) {
     530        free(pEdges);
    379531    }
    380532    SurfaceData_InvokeUnlock(env, dstOps, &dstInfo);
    381533    SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);
    382     if (!JNU_IsNull(env, edgeArray)) {
    383         (*env)->SetIntArrayRegion(env, edgeArray, 0, 1, &dstInfo.bounds.y1);
    384         (*env)->SetIntArrayRegion(env, edgeArray, 1, 1, &dstInfo.bounds.y2);
    385         (*env)->SetIntArrayRegion(env, edgeArray,
    386                                   2, (dstInfo.bounds.y2 - dstInfo.bounds.y1)*2,
    387                                   pEdges);
    388     }
    389     if (pEdges != edgebuf) {
    390         free(pEdges);
    391     }
     534}
     535
     536static void
     537Transform_SafeHelper(JNIEnv *env,
     538                     SurfaceDataOps *srcOps,
     539                     SurfaceDataOps *dstOps,
     540                     SurfaceDataRasInfo *pSrcInfo,
     541                     SurfaceDataRasInfo *pDstInfo,
     542                     NativePrimitive *pMaskBlitPrim,
     543                     CompositeInfo *pCompInfo,
     544                     TransformHelperFunc *pHelperFunc,
     545                     TransformInterpFunc *pInterpFunc,
     546                     RegionData *pClipInfo, TransformInfo *pItxInfo,
     547                     jint *pData, jint *pEdges,
     548                     jint dxoff, jint dyoff, jint sw, jint sh)
     549{
     550    SurfaceDataBounds span;
     551    jint dx1, dx2;
     552    jint dy1, dy2;
     553    jint i, iy;
     554
     555    dy1 = pDstInfo->bounds.y1;
     556    dy2 = pDstInfo->bounds.y2;
     557    dx1 = pDstInfo->bounds.x1;
     558    dx2 = pDstInfo->bounds.x2;
     559    pEdges[0] = dy1;
     560    pEdges[1] = dy2;
     561    for (iy = dy1; iy < dy2; iy++) {
     562        jint i = (iy - dy1) * 2;
     563        /* row spans are set to max,min until we find a pixel in range below */
     564        pEdges[i + 2] = dx2;
     565        pEdges[i + 3] = dx1;
     566    }
     567
     568    Region_StartIteration(env, pClipInfo);
     569    while (Region_NextIteration(pClipInfo, &span)) {
     570        dy1 = span.y1;
     571        dy2 = span.y2;
     572        while (dy1 < dy2) {
     573            dx1 = span.x1;
     574            dx2 = span.x2;
     575            i = (dy1 - pDstInfo->bounds.y1) * 2;
     576            while (dx1 < dx2) {
     577                jdouble x, y;
     578                jlong xlong, ylong;
     579
     580                x = dxoff + dx1 + 0.5;
     581                y = dyoff + dy1 + 0.5;
     582                Transform_transform(pItxInfo, &x, &y);
     583                xlong = DblToLong(x);
     584                ylong = DblToLong(y);
     585
     586                /* Process only pixels with centers in bounds
     587                 * Test double values to avoid overflow in conversion
     588                 * to long values and then also test the long values
     589                 * in case they rounded up and out of bounds during
     590                 * the conversion.
     591                 */
     592                if (x >= 0 && y >= 0 && x < sw && y < sh &&
     593                    WholeOfLong(xlong) < sw &&
     594                    WholeOfLong(ylong) < sh)
     595                {
     596                    void *pDst;
     597
     598                    if (pEdges[i + 2] > dx1) {
     599                        pEdges[i + 2] = dx1;
     600                    }
     601                    if (pEdges[i + 3] <= dx1) {
     602                        pEdges[i + 3] = dx1 + 1;
     603                    }
     604
     605                    /* Get IntArgbPre pixel data from source */
     606                    (*pHelperFunc)(pSrcInfo,
     607                                   pData, 1,
     608                                   xlong, 0,
     609                                   ylong, 0);
     610
     611                    /* Interpolate result pixels if needed */
     612                    if (pInterpFunc) {
     613                        (*pInterpFunc)(pData, 1,
     614                                       FractOfLong(xlong-LongOneHalf), 0,
     615                                       FractOfLong(ylong-LongOneHalf), 0);
     616                    }
     617
     618                    /* Store/Composite interpolated pixels into dest */
     619                    pDst = PtrCoord(pDstInfo->rasBase,
     620                                    dx1, pDstInfo->pixelStride,
     621                                    dy1, pDstInfo->scanStride);
     622                    (*pMaskBlitPrim->funcs.maskblit)(pDst, pData,
     623                                                     0, 0, 0,
     624                                                     1, 1,
     625                                                     pDstInfo, pSrcInfo,
     626                                                     pMaskBlitPrim,
     627                                                     pCompInfo);
     628                }
     629
     630                /* Increment to next input pixel */
     631                dx1++;
     632            }
     633
     634            /* Increment to next scanline */
     635            dy1++;
     636        }
     637    }
     638    Region_EndIteration(env, pClipInfo);
    392639}
    393640
Note: See TracChangeset for help on using the changeset viewer.