< prev index next >

src/share/native/sun/awt/libpng/pngerror.c

Print this page
rev 13661 : 8217676: Upgrade libpng to 1.6.37
Reviewed-by: prr, jdv, kcr


  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /* pngerror.c - stub functions for i/o and memory allocation
  26  *
  27  * This file is available under and governed by the GNU General Public
  28  * License version 2 only, as published by the Free Software Foundation.
  29  * However, the following notice accompanied the original version of this
  30  * file and, per its terms, should not be removed:
  31  *
  32  * Last changed in libpng 1.6.31 [July 27, 2017]
  33  * Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson
  34  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  35  * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  36  *
  37  * This code is released under the libpng license.
  38  * For conditions of distribution and use, see the disclaimer
  39  * and license in png.h
  40  *
  41  * This file provides a location for all error handling.  Users who
  42  * need special error handling are expected to write replacement functions
  43  * and use png_set_error_fn() to use those functions.  See the instructions
  44  * at each function.
  45  */
  46 
  47 #include "pngpriv.h"
  48 
  49 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  50 
  51 static PNG_FUNCTION(void, png_default_error,PNGARG((png_const_structrp png_ptr,
  52     png_const_charp error_message)),PNG_NORETURN);
  53 
  54 #ifdef PNG_WARNINGS_SUPPORTED
  55 static void /* PRIVATE */


 436       png_warning(png_ptr, error_message);
 437    else
 438       png_error(png_ptr, error_message);
 439 
 440 #  ifndef PNG_ERROR_TEXT_SUPPORTED
 441       PNG_UNUSED(error_message)
 442 #  endif
 443 }
 444 #endif /* BENIGN_ERRORS */
 445 
 446 #define PNG_MAX_ERROR_TEXT 196 /* Currently limited by profile_error in png.c */
 447 #if defined(PNG_WARNINGS_SUPPORTED) || \
 448    (defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED))
 449 /* These utilities are used internally to build an error message that relates
 450  * to the current chunk.  The chunk name comes from png_ptr->chunk_name,
 451  * which is used to prefix the message.  The message is limited in length
 452  * to 63 bytes. The name characters are output as hex digits wrapped in []
 453  * if the character is invalid.
 454  */
 455 #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
 456 static PNG_CONST char png_digit[16] = {
 457    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 458    'A', 'B', 'C', 'D', 'E', 'F'
 459 };
 460 
 461 static void /* PRIVATE */
 462 png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp
 463     error_message)
 464 {
 465    png_uint_32 chunk_name = png_ptr->chunk_name;
 466    int iout = 0, ishift = 24;
 467 
 468    while (ishift >= 0)
 469    {
 470       int c = (int)(chunk_name >> ishift) & 0xff;
 471 
 472       ishift -= 8;
 473       if (isnonalpha(c) != 0)
 474       {
 475          buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET;
 476          buffer[iout++] = png_digit[(c & 0xf0) >> 4];


 896 {
 897    if (png_ptr != NULL)
 898    {
 899       png_ptr->flags &=
 900          ((~(PNG_FLAG_STRIP_ERROR_NUMBERS |
 901          PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
 902    }
 903 }
 904 #endif
 905 
 906 #if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\
 907    defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
 908    /* Currently the above both depend on SETJMP_SUPPORTED, however it would be
 909     * possible to implement without setjmp support just so long as there is some
 910     * way to handle the error return here:
 911     */
 912 PNG_FUNCTION(void /* PRIVATE */, (PNGCBAPI
 913 png_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message),
 914     PNG_NORETURN)
 915 {
 916    const png_const_structrp png_ptr = png_nonconst_ptr;
 917    png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr);
 918 
 919    /* An error is always logged here, overwriting anything (typically a warning)
 920     * that is already there:
 921     */
 922    if (image != NULL)
 923    {
 924       png_safecat(image->message, (sizeof image->message), 0, error_message);
 925       image->warning_or_error |= PNG_IMAGE_ERROR;
 926 
 927       /* Retrieve the jmp_buf from within the png_control, making this work for
 928        * C++ compilation too is pretty tricky: C++ wants a pointer to the first
 929        * element of a jmp_buf, but C doesn't tell us the type of that.
 930        */
 931       if (image->opaque != NULL && image->opaque->error_buf != NULL)
 932          longjmp(png_control_jmp_buf(image->opaque), 1);
 933 
 934       /* Missing longjmp buffer, the following is to help debugging: */
 935       {
 936          size_t pos = png_safecat(image->message, (sizeof image->message), 0,
 937              "bad longjmp: ");
 938          png_safecat(image->message, (sizeof image->message), pos,
 939              error_message);
 940       }
 941    }
 942 
 943    /* Here on an internal programming error. */
 944    abort();
 945 }
 946 
 947 #ifdef PNG_WARNINGS_SUPPORTED
 948 void /* PRIVATE */ PNGCBAPI
 949 png_safe_warning(png_structp png_nonconst_ptr, png_const_charp warning_message)
 950 {
 951    const png_const_structrp png_ptr = png_nonconst_ptr;
 952    png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr);
 953 
 954    /* A warning is only logged if there is no prior warning or error. */
 955    if (image->warning_or_error == 0)
 956    {
 957       png_safecat(image->message, (sizeof image->message), 0, warning_message);
 958       image->warning_or_error |= PNG_IMAGE_WARNING;
 959    }
 960 }
 961 #endif
 962 
 963 int /* PRIVATE */
 964 png_safe_execute(png_imagep image_in, int (*function)(png_voidp), png_voidp arg)
 965 {
 966    volatile png_imagep image = image_in;
 967    volatile int result;
 968    volatile png_voidp saved_error_buf;
 969    jmp_buf safe_jmpbuf;
 970 
 971    /* Safely execute function(arg) with png_error returning to this function. */


  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /* pngerror.c - stub functions for i/o and memory allocation
  26  *
  27  * This file is available under and governed by the GNU General Public
  28  * License version 2 only, as published by the Free Software Foundation.
  29  * However, the following notice accompanied the original version of this
  30  * file and, per its terms, should not be removed:
  31  *
  32  * Copyright (c) 2018 Cosmin Truta
  33  * Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson
  34  * Copyright (c) 1996-1997 Andreas Dilger
  35  * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
  36  *
  37  * This code is released under the libpng license.
  38  * For conditions of distribution and use, see the disclaimer
  39  * and license in png.h
  40  *
  41  * This file provides a location for all error handling.  Users who
  42  * need special error handling are expected to write replacement functions
  43  * and use png_set_error_fn() to use those functions.  See the instructions
  44  * at each function.
  45  */
  46 
  47 #include "pngpriv.h"
  48 
  49 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  50 
  51 static PNG_FUNCTION(void, png_default_error,PNGARG((png_const_structrp png_ptr,
  52     png_const_charp error_message)),PNG_NORETURN);
  53 
  54 #ifdef PNG_WARNINGS_SUPPORTED
  55 static void /* PRIVATE */


 436       png_warning(png_ptr, error_message);
 437    else
 438       png_error(png_ptr, error_message);
 439 
 440 #  ifndef PNG_ERROR_TEXT_SUPPORTED
 441       PNG_UNUSED(error_message)
 442 #  endif
 443 }
 444 #endif /* BENIGN_ERRORS */
 445 
 446 #define PNG_MAX_ERROR_TEXT 196 /* Currently limited by profile_error in png.c */
 447 #if defined(PNG_WARNINGS_SUPPORTED) || \
 448    (defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED))
 449 /* These utilities are used internally to build an error message that relates
 450  * to the current chunk.  The chunk name comes from png_ptr->chunk_name,
 451  * which is used to prefix the message.  The message is limited in length
 452  * to 63 bytes. The name characters are output as hex digits wrapped in []
 453  * if the character is invalid.
 454  */
 455 #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
 456 static const char png_digit[16] = {
 457    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
 458    'A', 'B', 'C', 'D', 'E', 'F'
 459 };
 460 
 461 static void /* PRIVATE */
 462 png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp
 463     error_message)
 464 {
 465    png_uint_32 chunk_name = png_ptr->chunk_name;
 466    int iout = 0, ishift = 24;
 467 
 468    while (ishift >= 0)
 469    {
 470       int c = (int)(chunk_name >> ishift) & 0xff;
 471 
 472       ishift -= 8;
 473       if (isnonalpha(c) != 0)
 474       {
 475          buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET;
 476          buffer[iout++] = png_digit[(c & 0xf0) >> 4];


 896 {
 897    if (png_ptr != NULL)
 898    {
 899       png_ptr->flags &=
 900          ((~(PNG_FLAG_STRIP_ERROR_NUMBERS |
 901          PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
 902    }
 903 }
 904 #endif
 905 
 906 #if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\
 907    defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
 908    /* Currently the above both depend on SETJMP_SUPPORTED, however it would be
 909     * possible to implement without setjmp support just so long as there is some
 910     * way to handle the error return here:
 911     */
 912 PNG_FUNCTION(void /* PRIVATE */, (PNGCBAPI
 913 png_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message),
 914     PNG_NORETURN)
 915 {
 916    png_const_structrp png_ptr = png_nonconst_ptr;
 917    png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr);
 918 
 919    /* An error is always logged here, overwriting anything (typically a warning)
 920     * that is already there:
 921     */
 922    if (image != NULL)
 923    {
 924       png_safecat(image->message, (sizeof image->message), 0, error_message);
 925       image->warning_or_error |= PNG_IMAGE_ERROR;
 926 
 927       /* Retrieve the jmp_buf from within the png_control, making this work for
 928        * C++ compilation too is pretty tricky: C++ wants a pointer to the first
 929        * element of a jmp_buf, but C doesn't tell us the type of that.
 930        */
 931       if (image->opaque != NULL && image->opaque->error_buf != NULL)
 932          longjmp(png_control_jmp_buf(image->opaque), 1);
 933 
 934       /* Missing longjmp buffer, the following is to help debugging: */
 935       {
 936          size_t pos = png_safecat(image->message, (sizeof image->message), 0,
 937              "bad longjmp: ");
 938          png_safecat(image->message, (sizeof image->message), pos,
 939              error_message);
 940       }
 941    }
 942 
 943    /* Here on an internal programming error. */
 944    abort();
 945 }
 946 
 947 #ifdef PNG_WARNINGS_SUPPORTED
 948 void /* PRIVATE */ PNGCBAPI
 949 png_safe_warning(png_structp png_nonconst_ptr, png_const_charp warning_message)
 950 {
 951    png_const_structrp png_ptr = png_nonconst_ptr;
 952    png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr);
 953 
 954    /* A warning is only logged if there is no prior warning or error. */
 955    if (image->warning_or_error == 0)
 956    {
 957       png_safecat(image->message, (sizeof image->message), 0, warning_message);
 958       image->warning_or_error |= PNG_IMAGE_WARNING;
 959    }
 960 }
 961 #endif
 962 
 963 int /* PRIVATE */
 964 png_safe_execute(png_imagep image_in, int (*function)(png_voidp), png_voidp arg)
 965 {
 966    volatile png_imagep image = image_in;
 967    volatile int result;
 968    volatile png_voidp saved_error_buf;
 969    jmp_buf safe_jmpbuf;
 970 
 971    /* Safely execute function(arg) with png_error returning to this function. */
< prev index next >