Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: third_party/libpng/pngtest.c

Issue 2939383002: libpng: Reject oversized iCCP profile length (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libpng/pngpriv.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* pngtest.c - a simple test program to test libpng 2 /* pngtest.c - a simple test program to test libpng
3 * 3 *
4 * Last changed in libpng 1.5.25 [December 3, 2015] 4 * Last changed in libpng 1.5.25 [December 3, 2015]
5 * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson 5 * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 * 8 *
9 * This code is released under the libpng license. 9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer 10 * For conditions of distribution and use, see the disclaimer
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 */ 507 */
508 typedef struct memory_information 508 typedef struct memory_information
509 { 509 {
510 png_alloc_size_t size; 510 png_alloc_size_t size;
511 png_voidp pointer; 511 png_voidp pointer;
512 struct memory_information *next; 512 struct memory_information *next;
513 } memory_information; 513 } memory_information;
514 typedef memory_information *memory_infop; 514 typedef memory_information *memory_infop;
515 515
516 static memory_infop pinformation = NULL; 516 static memory_infop pinformation = NULL;
517 static int current_allocation = 0; 517 static png_alloc_size_t current_allocation = 0;
518 static int maximum_allocation = 0; 518 static png_alloc_size_t maximum_allocation = 0;
519 static int total_allocation = 0; 519 static png_alloc_size_t total_allocation = 0;
520 static int num_allocations = 0; 520 static png_alloc_size_t num_allocations = 0;
521 521
522 png_voidp PNGCBAPI png_debug_malloc PNGARG((png_structp png_ptr, 522 png_voidp PNGCBAPI png_debug_malloc PNGARG((png_structp png_ptr,
523 png_alloc_size_t size)); 523 png_alloc_size_t size));
524 void PNGCBAPI png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr)); 524 void PNGCBAPI png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr));
525 525
526 png_voidp 526 png_voidp
527 PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size) 527 PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
528 { 528 {
529 529
530 /* png_malloc has already tested for NULL; png_create_struct calls 530 /* png_malloc has already tested for NULL; png_create_struct calls
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 { 597 {
598 memory_infop *ppinfo = &pinformation; 598 memory_infop *ppinfo = &pinformation;
599 599
600 for (;;) 600 for (;;)
601 { 601 {
602 memory_infop pinfo = *ppinfo; 602 memory_infop pinfo = *ppinfo;
603 603
604 if (pinfo->pointer == ptr) 604 if (pinfo->pointer == ptr)
605 { 605 {
606 *ppinfo = pinfo->next; 606 *ppinfo = pinfo->next;
607 current_allocation -= pinfo->size; 607 if (current_allocation < pinfo->size)
608 if (current_allocation < 0)
609 fprintf(STDERR, "Duplicate free of memory\n"); 608 fprintf(STDERR, "Duplicate free of memory\n");
609 else
610 current_allocation -= pinfo->size;
610 /* We must free the list element too, but first kill 611 /* We must free the list element too, but first kill
611 the memory that is to be freed. */ 612 the memory that is to be freed. */
612 memset(ptr, 0x55, pinfo->size); 613 memset(ptr, 0x55, pinfo->size);
613 free(pinfo); 614 free(pinfo);
614 pinfo = NULL; 615 pinfo = NULL;
615 break; 616 break;
616 } 617 }
617 618
618 if (pinfo->next == NULL) 619 if (pinfo->next == NULL)
619 { 620 {
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 write_info_ptr = png_create_info_struct(write_ptr); 932 write_info_ptr = png_create_info_struct(write_ptr);
932 write_end_info_ptr = png_create_info_struct(write_ptr); 933 write_end_info_ptr = png_create_info_struct(write_ptr);
933 #endif 934 #endif
934 935
935 #ifdef PNG_READ_USER_CHUNKS_SUPPORTED 936 #ifdef PNG_READ_USER_CHUNKS_SUPPORTED
936 init_callback_info(read_info_ptr); 937 init_callback_info(read_info_ptr);
937 png_set_read_user_chunk_fn(read_ptr, &user_chunk_data, 938 png_set_read_user_chunk_fn(read_ptr, &user_chunk_data,
938 read_user_chunk_callback); 939 read_user_chunk_callback);
939 #endif 940 #endif
940 941
942 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
943 # ifdef CHUNK_LIMIT /* from the build, for testing */
944 png_set_chunk_malloc_max(read_ptr, CHUNK_LIMIT);
945 # endif /* CHUNK_LIMIT */
946 #endif
947
941 #ifdef PNG_SETJMP_SUPPORTED 948 #ifdef PNG_SETJMP_SUPPORTED
942 pngtest_debug("Setting jmpbuf for read struct"); 949 pngtest_debug("Setting jmpbuf for read struct");
943 if (setjmp(png_jmpbuf(read_ptr))) 950 if (setjmp(png_jmpbuf(read_ptr)))
944 { 951 {
945 fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname); 952 fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);
946 png_free(read_ptr, row_buf); 953 png_free(read_ptr, row_buf);
947 row_buf = NULL; 954 row_buf = NULL;
948 png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); 955 png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
949 #ifdef PNG_WRITE_SUPPORTED 956 #ifdef PNG_WRITE_SUPPORTED
950 png_destroy_info_struct(write_ptr, &write_end_info_ptr); 957 png_destroy_info_struct(write_ptr, &write_end_info_ptr);
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
1867 " reads/writes one PNG file (without -m) or multiple files (-m)\n"); 1874 " reads/writes one PNG file (without -m) or multiple files (-m)\n");
1868 fprintf(STDERR, 1875 fprintf(STDERR,
1869 " with -m %s is used as a temporary file\n", outname); 1876 " with -m %s is used as a temporary file\n", outname);
1870 exit(1); 1877 exit(1);
1871 } 1878 }
1872 1879
1873 if (multiple != 0) 1880 if (multiple != 0)
1874 { 1881 {
1875 int i; 1882 int i;
1876 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG 1883 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1877 int allocation_now = current_allocation; 1884 png_alloc_size_t allocation_now = current_allocation;
1878 #endif 1885 #endif
1879 for (i=2; i<argc; ++i) 1886 for (i=2; i<argc; ++i)
1880 { 1887 {
1881 int kerror; 1888 int kerror;
1882 fprintf(STDERR, "\n Testing %s:", argv[i]); 1889 fprintf(STDERR, "\n Testing %s:", argv[i]);
1883 #if PNG_DEBUG > 0 1890 #if PNG_DEBUG > 0
1884 fprintf(STDERR, "\n"); 1891 fprintf(STDERR, "\n");
1885 #endif 1892 #endif
1886 kerror = test_one_file(argv[i], outname); 1893 kerror = test_one_file(argv[i], outname);
1887 if (kerror == 0) 1894 if (kerror == 0)
(...skipping 12 matching lines...) Expand all
1900 #endif /* TIME_RFC1123 */ 1907 #endif /* TIME_RFC1123 */
1901 } 1908 }
1902 1909
1903 else 1910 else
1904 { 1911 {
1905 fprintf(STDERR, " FAIL\n"); 1912 fprintf(STDERR, " FAIL\n");
1906 ierror += kerror; 1913 ierror += kerror;
1907 } 1914 }
1908 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG 1915 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1909 if (allocation_now != current_allocation) 1916 if (allocation_now != current_allocation)
1910 fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n", 1917 fprintf(STDERR, "MEMORY ERROR: %lu bytes lost\n",
1911 current_allocation - allocation_now); 1918 (unsigned long)(current_allocation - allocation_now));
1912 1919
1913 if (current_allocation != 0) 1920 if (current_allocation != 0)
1914 { 1921 {
1915 memory_infop pinfo = pinformation; 1922 memory_infop pinfo = pinformation;
1916 1923
1917 fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n", 1924 fprintf(STDERR, "MEMORY ERROR: %lu bytes still allocated\n",
1918 current_allocation); 1925 (unsigned long)current_allocation);
1919 1926
1920 while (pinfo != NULL) 1927 while (pinfo != NULL)
1921 { 1928 {
1922 fprintf(STDERR, " %lu bytes at %p\n", 1929 fprintf(STDERR, " %lu bytes at %p\n",
1923 (unsigned long)pinfo->size, 1930 (unsigned long)pinfo->size,
1924 pinfo->pointer); 1931 pinfo->pointer);
1925 pinfo = pinfo->next; 1932 pinfo = pinfo->next;
1926 } 1933 }
1927 } 1934 }
1928 #endif 1935 #endif
1929 } 1936 }
1930 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG 1937 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1931 fprintf(STDERR, " Current memory allocation: %10d bytes\n", 1938 fprintf(STDERR, " Current memory allocation: %20lu bytes\n",
1932 current_allocation); 1939 (unsigned long)current_allocation);
1933 fprintf(STDERR, " Maximum memory allocation: %10d bytes\n", 1940 fprintf(STDERR, " Maximum memory allocation: %20lu bytes\n",
1934 maximum_allocation); 1941 (unsigned long) maximum_allocation);
1935 fprintf(STDERR, " Total memory allocation: %10d bytes\n", 1942 fprintf(STDERR, " Total memory allocation: %20lu bytes\n",
1936 total_allocation); 1943 (unsigned long)total_allocation);
1937 fprintf(STDERR, " Number of allocations: %10d\n", 1944 fprintf(STDERR, " Number of allocations: %20lu\n",
1938 num_allocations); 1945 (unsigned long)num_allocations);
1939 #endif 1946 #endif
1940 } 1947 }
1941 1948
1942 else 1949 else
1943 { 1950 {
1944 int i; 1951 int i;
1945 for (i = 0; i<3; ++i) 1952 for (i = 0; i<3; ++i)
1946 { 1953 {
1947 int kerror; 1954 int kerror;
1948 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG 1955 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1949 int allocation_now = current_allocation; 1956 png_alloc_size_t allocation_now = current_allocation;
1950 #endif 1957 #endif
1951 if (i == 1) 1958 if (i == 1)
1952 status_dots_requested = 1; 1959 status_dots_requested = 1;
1953 1960
1954 else if (verbose == 0) 1961 else if (verbose == 0)
1955 status_dots_requested = 0; 1962 status_dots_requested = 0;
1956 1963
1957 if (i == 0 || verbose == 1 || ierror != 0) 1964 if (i == 0 || verbose == 1 || ierror != 0)
1958 { 1965 {
1959 fprintf(STDERR, "\n Testing %s:", inname); 1966 fprintf(STDERR, "\n Testing %s:", inname);
(...skipping 29 matching lines...) Expand all
1989 #if PNG_DEBUG > 0 1996 #if PNG_DEBUG > 0
1990 fprintf(STDERR, "\n"); 1997 fprintf(STDERR, "\n");
1991 #endif 1998 #endif
1992 } 1999 }
1993 2000
1994 fprintf(STDERR, " FAIL\n"); 2001 fprintf(STDERR, " FAIL\n");
1995 ierror += kerror; 2002 ierror += kerror;
1996 } 2003 }
1997 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG 2004 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1998 if (allocation_now != current_allocation) 2005 if (allocation_now != current_allocation)
1999 fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n", 2006 fprintf(STDERR, "MEMORY ERROR: %lu bytes lost\n",
2000 current_allocation - allocation_now); 2007 (unsigned long)(current_allocation - allocation_now));
2001 2008
2002 if (current_allocation != 0) 2009 if (current_allocation != 0)
2003 { 2010 {
2004 memory_infop pinfo = pinformation; 2011 memory_infop pinfo = pinformation;
2005 2012
2006 fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n", 2013 fprintf(STDERR, "MEMORY ERROR: %lu bytes still allocated\n",
2007 current_allocation); 2014 (unsigned long)current_allocation);
2008 2015
2009 while (pinfo != NULL) 2016 while (pinfo != NULL)
2010 { 2017 {
2011 fprintf(STDERR, " %lu bytes at %p\n", 2018 fprintf(STDERR, " %lu bytes at %p\n",
2012 (unsigned long)pinfo->size, pinfo->pointer); 2019 (unsigned long)pinfo->size, pinfo->pointer);
2013 pinfo = pinfo->next; 2020 pinfo = pinfo->next;
2014 } 2021 }
2015 } 2022 }
2016 #endif 2023 #endif
2017 } 2024 }
2018 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG 2025 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
2019 fprintf(STDERR, " Current memory allocation: %10d bytes\n", 2026 fprintf(STDERR, " Current memory allocation: %20lu bytes\n",
2020 current_allocation); 2027 (unsigned long)current_allocation);
2021 fprintf(STDERR, " Maximum memory allocation: %10d bytes\n", 2028 fprintf(STDERR, " Maximum memory allocation: %20lu bytes\n",
2022 maximum_allocation); 2029 (unsigned long)maximum_allocation);
2023 fprintf(STDERR, " Total memory allocation: %10d bytes\n", 2030 fprintf(STDERR, " Total memory allocation: %20lu bytes\n",
2024 total_allocation); 2031 (unsigned long)total_allocation);
2025 fprintf(STDERR, " Number of allocations: %10d\n", 2032 fprintf(STDERR, " Number of allocations: %20lu\n",
2026 num_allocations); 2033 (unsigned long)num_allocations);
2027 #endif 2034 #endif
2028 } 2035 }
2029 2036
2030 #ifdef PNGTEST_TIMING 2037 #ifdef PNGTEST_TIMING
2031 t_stop = (float)clock(); 2038 t_stop = (float)clock();
2032 t_misc += (t_stop - t_start); 2039 t_misc += (t_stop - t_start);
2033 t_start = t_stop; 2040 t_start = t_stop;
2034 fprintf(STDERR, " CPU time used = %.3f seconds", 2041 fprintf(STDERR, " CPU time used = %.3f seconds",
2035 (t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC); 2042 (t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC);
2036 fprintf(STDERR, " (decoding %.3f,\n", 2043 fprintf(STDERR, " (decoding %.3f,\n",
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2073 { 2080 {
2074 fprintf(STDERR, 2081 fprintf(STDERR,
2075 " test ignored because libpng was not built with read support\n"); 2082 " test ignored because libpng was not built with read support\n");
2076 /* And skip this test */ 2083 /* And skip this test */
2077 return SKIP; 2084 return SKIP;
2078 } 2085 }
2079 #endif 2086 #endif
2080 2087
2081 /* Generate a compiler error if there is an old png.h in the search path. */ 2088 /* Generate a compiler error if there is an old png.h in the search path. */
2082 typedef png_libpng_version_1_6_22 Your_png_h_is_not_version_1_6_22; 2089 typedef png_libpng_version_1_6_22 Your_png_h_is_not_version_1_6_22;
OLDNEW
« no previous file with comments | « third_party/libpng/pngpriv.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698