1*a67afe4dSAndroid Build Coastguard Worker
2*a67afe4dSAndroid Build Coastguard Worker /* pngmem.c - stub functions for memory allocation
3*a67afe4dSAndroid Build Coastguard Worker *
4*a67afe4dSAndroid Build Coastguard Worker * Copyright (c) 2018 Cosmin Truta
5*a67afe4dSAndroid Build Coastguard Worker * Copyright (c) 1998-2002,2004,2006-2014,2016 Glenn Randers-Pehrson
6*a67afe4dSAndroid Build Coastguard Worker * Copyright (c) 1996-1997 Andreas Dilger
7*a67afe4dSAndroid Build Coastguard Worker * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
8*a67afe4dSAndroid Build Coastguard Worker *
9*a67afe4dSAndroid Build Coastguard Worker * This code is released under the libpng license.
10*a67afe4dSAndroid Build Coastguard Worker * For conditions of distribution and use, see the disclaimer
11*a67afe4dSAndroid Build Coastguard Worker * and license in png.h
12*a67afe4dSAndroid Build Coastguard Worker *
13*a67afe4dSAndroid Build Coastguard Worker * This file provides a location for all memory allocation. Users who
14*a67afe4dSAndroid Build Coastguard Worker * need special memory handling are expected to supply replacement
15*a67afe4dSAndroid Build Coastguard Worker * functions for png_malloc() and png_free(), and to use
16*a67afe4dSAndroid Build Coastguard Worker * png_create_read_struct_2() and png_create_write_struct_2() to
17*a67afe4dSAndroid Build Coastguard Worker * identify the replacement functions.
18*a67afe4dSAndroid Build Coastguard Worker */
19*a67afe4dSAndroid Build Coastguard Worker
20*a67afe4dSAndroid Build Coastguard Worker #include "pngpriv.h"
21*a67afe4dSAndroid Build Coastguard Worker
22*a67afe4dSAndroid Build Coastguard Worker #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
23*a67afe4dSAndroid Build Coastguard Worker /* Free a png_struct */
24*a67afe4dSAndroid Build Coastguard Worker void /* PRIVATE */
png_destroy_png_struct(png_structrp png_ptr)25*a67afe4dSAndroid Build Coastguard Worker png_destroy_png_struct(png_structrp png_ptr)
26*a67afe4dSAndroid Build Coastguard Worker {
27*a67afe4dSAndroid Build Coastguard Worker if (png_ptr != NULL)
28*a67afe4dSAndroid Build Coastguard Worker {
29*a67afe4dSAndroid Build Coastguard Worker /* png_free might call png_error and may certainly call
30*a67afe4dSAndroid Build Coastguard Worker * png_get_mem_ptr, so fake a temporary png_struct to support this.
31*a67afe4dSAndroid Build Coastguard Worker */
32*a67afe4dSAndroid Build Coastguard Worker png_struct dummy_struct = *png_ptr;
33*a67afe4dSAndroid Build Coastguard Worker memset(png_ptr, 0, (sizeof *png_ptr));
34*a67afe4dSAndroid Build Coastguard Worker png_free(&dummy_struct, png_ptr);
35*a67afe4dSAndroid Build Coastguard Worker
36*a67afe4dSAndroid Build Coastguard Worker # ifdef PNG_SETJMP_SUPPORTED
37*a67afe4dSAndroid Build Coastguard Worker /* We may have a jmp_buf left to deallocate. */
38*a67afe4dSAndroid Build Coastguard Worker png_free_jmpbuf(&dummy_struct);
39*a67afe4dSAndroid Build Coastguard Worker # endif
40*a67afe4dSAndroid Build Coastguard Worker }
41*a67afe4dSAndroid Build Coastguard Worker }
42*a67afe4dSAndroid Build Coastguard Worker
43*a67afe4dSAndroid Build Coastguard Worker /* Allocate memory. For reasonable files, size should never exceed
44*a67afe4dSAndroid Build Coastguard Worker * 64K. However, zlib may allocate more than 64K if you don't tell
45*a67afe4dSAndroid Build Coastguard Worker * it not to. See zconf.h and png.h for more information. zlib does
46*a67afe4dSAndroid Build Coastguard Worker * need to allocate exactly 64K, so whatever you call here must
47*a67afe4dSAndroid Build Coastguard Worker * have the ability to do that.
48*a67afe4dSAndroid Build Coastguard Worker */
49*a67afe4dSAndroid Build Coastguard Worker PNG_FUNCTION(png_voidp,PNGAPI
50*a67afe4dSAndroid Build Coastguard Worker png_calloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
51*a67afe4dSAndroid Build Coastguard Worker {
52*a67afe4dSAndroid Build Coastguard Worker png_voidp ret;
53*a67afe4dSAndroid Build Coastguard Worker
54*a67afe4dSAndroid Build Coastguard Worker ret = png_malloc(png_ptr, size);
55*a67afe4dSAndroid Build Coastguard Worker
56*a67afe4dSAndroid Build Coastguard Worker if (ret != NULL)
57*a67afe4dSAndroid Build Coastguard Worker memset(ret, 0, size);
58*a67afe4dSAndroid Build Coastguard Worker
59*a67afe4dSAndroid Build Coastguard Worker return ret;
60*a67afe4dSAndroid Build Coastguard Worker }
61*a67afe4dSAndroid Build Coastguard Worker
62*a67afe4dSAndroid Build Coastguard Worker /* png_malloc_base, an internal function added at libpng 1.6.0, does the work of
63*a67afe4dSAndroid Build Coastguard Worker * allocating memory, taking into account limits and PNG_USER_MEM_SUPPORTED.
64*a67afe4dSAndroid Build Coastguard Worker * Checking and error handling must happen outside this routine; it returns NULL
65*a67afe4dSAndroid Build Coastguard Worker * if the allocation cannot be done (for any reason.)
66*a67afe4dSAndroid Build Coastguard Worker */
67*a67afe4dSAndroid Build Coastguard Worker PNG_FUNCTION(png_voidp /* PRIVATE */,
68*a67afe4dSAndroid Build Coastguard Worker png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size),
69*a67afe4dSAndroid Build Coastguard Worker PNG_ALLOCATED)
70*a67afe4dSAndroid Build Coastguard Worker {
71*a67afe4dSAndroid Build Coastguard Worker /* Moved to png_malloc_base from png_malloc_default in 1.6.0; the DOS
72*a67afe4dSAndroid Build Coastguard Worker * allocators have also been removed in 1.6.0, so any 16-bit system now has
73*a67afe4dSAndroid Build Coastguard Worker * to implement a user memory handler. This checks to be sure it isn't
74*a67afe4dSAndroid Build Coastguard Worker * called with big numbers.
75*a67afe4dSAndroid Build Coastguard Worker */
76*a67afe4dSAndroid Build Coastguard Worker #ifndef PNG_USER_MEM_SUPPORTED
77*a67afe4dSAndroid Build Coastguard Worker PNG_UNUSED(png_ptr)
78*a67afe4dSAndroid Build Coastguard Worker #endif
79*a67afe4dSAndroid Build Coastguard Worker
80*a67afe4dSAndroid Build Coastguard Worker /* Some compilers complain that this is always true. However, it
81*a67afe4dSAndroid Build Coastguard Worker * can be false when integer overflow happens.
82*a67afe4dSAndroid Build Coastguard Worker */
83*a67afe4dSAndroid Build Coastguard Worker if (size > 0 && size <= PNG_SIZE_MAX
84*a67afe4dSAndroid Build Coastguard Worker # ifdef PNG_MAX_MALLOC_64K
85*a67afe4dSAndroid Build Coastguard Worker && size <= 65536U
86*a67afe4dSAndroid Build Coastguard Worker # endif
87*a67afe4dSAndroid Build Coastguard Worker )
88*a67afe4dSAndroid Build Coastguard Worker {
89*a67afe4dSAndroid Build Coastguard Worker #ifdef PNG_USER_MEM_SUPPORTED
90*a67afe4dSAndroid Build Coastguard Worker if (png_ptr != NULL && png_ptr->malloc_fn != NULL)
91*a67afe4dSAndroid Build Coastguard Worker return png_ptr->malloc_fn(png_constcast(png_structrp,png_ptr), size);
92*a67afe4dSAndroid Build Coastguard Worker
93*a67afe4dSAndroid Build Coastguard Worker else
94*a67afe4dSAndroid Build Coastguard Worker #endif
95*a67afe4dSAndroid Build Coastguard Worker return malloc((size_t)size); /* checked for truncation above */
96*a67afe4dSAndroid Build Coastguard Worker }
97*a67afe4dSAndroid Build Coastguard Worker
98*a67afe4dSAndroid Build Coastguard Worker else
99*a67afe4dSAndroid Build Coastguard Worker return NULL;
100*a67afe4dSAndroid Build Coastguard Worker }
101*a67afe4dSAndroid Build Coastguard Worker
102*a67afe4dSAndroid Build Coastguard Worker #if defined(PNG_TEXT_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) ||\
103*a67afe4dSAndroid Build Coastguard Worker defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED)
104*a67afe4dSAndroid Build Coastguard Worker /* This is really here only to work round a spurious warning in GCC 4.6 and 4.7
105*a67afe4dSAndroid Build Coastguard Worker * that arises because of the checks in png_realloc_array that are repeated in
106*a67afe4dSAndroid Build Coastguard Worker * png_malloc_array.
107*a67afe4dSAndroid Build Coastguard Worker */
108*a67afe4dSAndroid Build Coastguard Worker static png_voidp
png_malloc_array_checked(png_const_structrp png_ptr,int nelements,size_t element_size)109*a67afe4dSAndroid Build Coastguard Worker png_malloc_array_checked(png_const_structrp png_ptr, int nelements,
110*a67afe4dSAndroid Build Coastguard Worker size_t element_size)
111*a67afe4dSAndroid Build Coastguard Worker {
112*a67afe4dSAndroid Build Coastguard Worker png_alloc_size_t req = (png_alloc_size_t)nelements; /* known to be > 0 */
113*a67afe4dSAndroid Build Coastguard Worker
114*a67afe4dSAndroid Build Coastguard Worker if (req <= PNG_SIZE_MAX/element_size)
115*a67afe4dSAndroid Build Coastguard Worker return png_malloc_base(png_ptr, req * element_size);
116*a67afe4dSAndroid Build Coastguard Worker
117*a67afe4dSAndroid Build Coastguard Worker /* The failure case when the request is too large */
118*a67afe4dSAndroid Build Coastguard Worker return NULL;
119*a67afe4dSAndroid Build Coastguard Worker }
120*a67afe4dSAndroid Build Coastguard Worker
121*a67afe4dSAndroid Build Coastguard Worker PNG_FUNCTION(png_voidp /* PRIVATE */,
122*a67afe4dSAndroid Build Coastguard Worker png_malloc_array,(png_const_structrp png_ptr, int nelements,
123*a67afe4dSAndroid Build Coastguard Worker size_t element_size),PNG_ALLOCATED)
124*a67afe4dSAndroid Build Coastguard Worker {
125*a67afe4dSAndroid Build Coastguard Worker if (nelements <= 0 || element_size == 0)
126*a67afe4dSAndroid Build Coastguard Worker png_error(png_ptr, "internal error: array alloc");
127*a67afe4dSAndroid Build Coastguard Worker
128*a67afe4dSAndroid Build Coastguard Worker return png_malloc_array_checked(png_ptr, nelements, element_size);
129*a67afe4dSAndroid Build Coastguard Worker }
130*a67afe4dSAndroid Build Coastguard Worker
131*a67afe4dSAndroid Build Coastguard Worker PNG_FUNCTION(png_voidp /* PRIVATE */,
132*a67afe4dSAndroid Build Coastguard Worker png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array,
133*a67afe4dSAndroid Build Coastguard Worker int old_elements, int add_elements, size_t element_size),PNG_ALLOCATED)
134*a67afe4dSAndroid Build Coastguard Worker {
135*a67afe4dSAndroid Build Coastguard Worker /* These are internal errors: */
136*a67afe4dSAndroid Build Coastguard Worker if (add_elements <= 0 || element_size == 0 || old_elements < 0 ||
137*a67afe4dSAndroid Build Coastguard Worker (old_array == NULL && old_elements > 0))
138*a67afe4dSAndroid Build Coastguard Worker png_error(png_ptr, "internal error: array realloc");
139*a67afe4dSAndroid Build Coastguard Worker
140*a67afe4dSAndroid Build Coastguard Worker /* Check for overflow on the elements count (so the caller does not have to
141*a67afe4dSAndroid Build Coastguard Worker * check.)
142*a67afe4dSAndroid Build Coastguard Worker */
143*a67afe4dSAndroid Build Coastguard Worker if (add_elements <= INT_MAX - old_elements)
144*a67afe4dSAndroid Build Coastguard Worker {
145*a67afe4dSAndroid Build Coastguard Worker png_voidp new_array = png_malloc_array_checked(png_ptr,
146*a67afe4dSAndroid Build Coastguard Worker old_elements+add_elements, element_size);
147*a67afe4dSAndroid Build Coastguard Worker
148*a67afe4dSAndroid Build Coastguard Worker if (new_array != NULL)
149*a67afe4dSAndroid Build Coastguard Worker {
150*a67afe4dSAndroid Build Coastguard Worker /* Because png_malloc_array worked the size calculations below cannot
151*a67afe4dSAndroid Build Coastguard Worker * overflow.
152*a67afe4dSAndroid Build Coastguard Worker */
153*a67afe4dSAndroid Build Coastguard Worker if (old_elements > 0)
154*a67afe4dSAndroid Build Coastguard Worker memcpy(new_array, old_array, element_size*(unsigned)old_elements);
155*a67afe4dSAndroid Build Coastguard Worker
156*a67afe4dSAndroid Build Coastguard Worker memset((char*)new_array + element_size*(unsigned)old_elements, 0,
157*a67afe4dSAndroid Build Coastguard Worker element_size*(unsigned)add_elements);
158*a67afe4dSAndroid Build Coastguard Worker
159*a67afe4dSAndroid Build Coastguard Worker return new_array;
160*a67afe4dSAndroid Build Coastguard Worker }
161*a67afe4dSAndroid Build Coastguard Worker }
162*a67afe4dSAndroid Build Coastguard Worker
163*a67afe4dSAndroid Build Coastguard Worker return NULL; /* error */
164*a67afe4dSAndroid Build Coastguard Worker }
165*a67afe4dSAndroid Build Coastguard Worker #endif /* TEXT || sPLT || STORE_UNKNOWN_CHUNKS */
166*a67afe4dSAndroid Build Coastguard Worker
167*a67afe4dSAndroid Build Coastguard Worker /* Various functions that have different error handling are derived from this.
168*a67afe4dSAndroid Build Coastguard Worker * png_malloc always exists, but if PNG_USER_MEM_SUPPORTED is defined a separate
169*a67afe4dSAndroid Build Coastguard Worker * function png_malloc_default is also provided.
170*a67afe4dSAndroid Build Coastguard Worker */
171*a67afe4dSAndroid Build Coastguard Worker PNG_FUNCTION(png_voidp,PNGAPI
172*a67afe4dSAndroid Build Coastguard Worker png_malloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
173*a67afe4dSAndroid Build Coastguard Worker {
174*a67afe4dSAndroid Build Coastguard Worker png_voidp ret;
175*a67afe4dSAndroid Build Coastguard Worker
176*a67afe4dSAndroid Build Coastguard Worker if (png_ptr == NULL)
177*a67afe4dSAndroid Build Coastguard Worker return NULL;
178*a67afe4dSAndroid Build Coastguard Worker
179*a67afe4dSAndroid Build Coastguard Worker ret = png_malloc_base(png_ptr, size);
180*a67afe4dSAndroid Build Coastguard Worker
181*a67afe4dSAndroid Build Coastguard Worker if (ret == NULL)
182*a67afe4dSAndroid Build Coastguard Worker png_error(png_ptr, "Out of memory"); /* 'm' means png_malloc */
183*a67afe4dSAndroid Build Coastguard Worker
184*a67afe4dSAndroid Build Coastguard Worker return ret;
185*a67afe4dSAndroid Build Coastguard Worker }
186*a67afe4dSAndroid Build Coastguard Worker
187*a67afe4dSAndroid Build Coastguard Worker #ifdef PNG_USER_MEM_SUPPORTED
188*a67afe4dSAndroid Build Coastguard Worker PNG_FUNCTION(png_voidp,PNGAPI
189*a67afe4dSAndroid Build Coastguard Worker png_malloc_default,(png_const_structrp png_ptr, png_alloc_size_t size),
190*a67afe4dSAndroid Build Coastguard Worker PNG_ALLOCATED PNG_DEPRECATED)
191*a67afe4dSAndroid Build Coastguard Worker {
192*a67afe4dSAndroid Build Coastguard Worker png_voidp ret;
193*a67afe4dSAndroid Build Coastguard Worker
194*a67afe4dSAndroid Build Coastguard Worker if (png_ptr == NULL)
195*a67afe4dSAndroid Build Coastguard Worker return NULL;
196*a67afe4dSAndroid Build Coastguard Worker
197*a67afe4dSAndroid Build Coastguard Worker /* Passing 'NULL' here bypasses the application provided memory handler. */
198*a67afe4dSAndroid Build Coastguard Worker ret = png_malloc_base(NULL/*use malloc*/, size);
199*a67afe4dSAndroid Build Coastguard Worker
200*a67afe4dSAndroid Build Coastguard Worker if (ret == NULL)
201*a67afe4dSAndroid Build Coastguard Worker png_error(png_ptr, "Out of Memory"); /* 'M' means png_malloc_default */
202*a67afe4dSAndroid Build Coastguard Worker
203*a67afe4dSAndroid Build Coastguard Worker return ret;
204*a67afe4dSAndroid Build Coastguard Worker }
205*a67afe4dSAndroid Build Coastguard Worker #endif /* USER_MEM */
206*a67afe4dSAndroid Build Coastguard Worker
207*a67afe4dSAndroid Build Coastguard Worker /* This function was added at libpng version 1.2.3. The png_malloc_warn()
208*a67afe4dSAndroid Build Coastguard Worker * function will issue a png_warning and return NULL instead of issuing a
209*a67afe4dSAndroid Build Coastguard Worker * png_error, if it fails to allocate the requested memory.
210*a67afe4dSAndroid Build Coastguard Worker */
211*a67afe4dSAndroid Build Coastguard Worker PNG_FUNCTION(png_voidp,PNGAPI
212*a67afe4dSAndroid Build Coastguard Worker png_malloc_warn,(png_const_structrp png_ptr, png_alloc_size_t size),
213*a67afe4dSAndroid Build Coastguard Worker PNG_ALLOCATED)
214*a67afe4dSAndroid Build Coastguard Worker {
215*a67afe4dSAndroid Build Coastguard Worker if (png_ptr != NULL)
216*a67afe4dSAndroid Build Coastguard Worker {
217*a67afe4dSAndroid Build Coastguard Worker png_voidp ret = png_malloc_base(png_ptr, size);
218*a67afe4dSAndroid Build Coastguard Worker
219*a67afe4dSAndroid Build Coastguard Worker if (ret != NULL)
220*a67afe4dSAndroid Build Coastguard Worker return ret;
221*a67afe4dSAndroid Build Coastguard Worker
222*a67afe4dSAndroid Build Coastguard Worker png_warning(png_ptr, "Out of memory");
223*a67afe4dSAndroid Build Coastguard Worker }
224*a67afe4dSAndroid Build Coastguard Worker
225*a67afe4dSAndroid Build Coastguard Worker return NULL;
226*a67afe4dSAndroid Build Coastguard Worker }
227*a67afe4dSAndroid Build Coastguard Worker
228*a67afe4dSAndroid Build Coastguard Worker /* Free a pointer allocated by png_malloc(). If ptr is NULL, return
229*a67afe4dSAndroid Build Coastguard Worker * without taking any action.
230*a67afe4dSAndroid Build Coastguard Worker */
231*a67afe4dSAndroid Build Coastguard Worker void PNGAPI
png_free(png_const_structrp png_ptr,png_voidp ptr)232*a67afe4dSAndroid Build Coastguard Worker png_free(png_const_structrp png_ptr, png_voidp ptr)
233*a67afe4dSAndroid Build Coastguard Worker {
234*a67afe4dSAndroid Build Coastguard Worker if (png_ptr == NULL || ptr == NULL)
235*a67afe4dSAndroid Build Coastguard Worker return;
236*a67afe4dSAndroid Build Coastguard Worker
237*a67afe4dSAndroid Build Coastguard Worker #ifdef PNG_USER_MEM_SUPPORTED
238*a67afe4dSAndroid Build Coastguard Worker if (png_ptr->free_fn != NULL)
239*a67afe4dSAndroid Build Coastguard Worker png_ptr->free_fn(png_constcast(png_structrp,png_ptr), ptr);
240*a67afe4dSAndroid Build Coastguard Worker
241*a67afe4dSAndroid Build Coastguard Worker else
242*a67afe4dSAndroid Build Coastguard Worker png_free_default(png_ptr, ptr);
243*a67afe4dSAndroid Build Coastguard Worker }
244*a67afe4dSAndroid Build Coastguard Worker
245*a67afe4dSAndroid Build Coastguard Worker PNG_FUNCTION(void,PNGAPI
246*a67afe4dSAndroid Build Coastguard Worker png_free_default,(png_const_structrp png_ptr, png_voidp ptr),PNG_DEPRECATED)
247*a67afe4dSAndroid Build Coastguard Worker {
248*a67afe4dSAndroid Build Coastguard Worker if (png_ptr == NULL || ptr == NULL)
249*a67afe4dSAndroid Build Coastguard Worker return;
250*a67afe4dSAndroid Build Coastguard Worker #endif /* USER_MEM */
251*a67afe4dSAndroid Build Coastguard Worker
252*a67afe4dSAndroid Build Coastguard Worker free(ptr);
253*a67afe4dSAndroid Build Coastguard Worker }
254*a67afe4dSAndroid Build Coastguard Worker
255*a67afe4dSAndroid Build Coastguard Worker #ifdef PNG_USER_MEM_SUPPORTED
256*a67afe4dSAndroid Build Coastguard Worker /* This function is called when the application wants to use another method
257*a67afe4dSAndroid Build Coastguard Worker * of allocating and freeing memory.
258*a67afe4dSAndroid Build Coastguard Worker */
259*a67afe4dSAndroid Build Coastguard Worker void PNGAPI
png_set_mem_fn(png_structrp png_ptr,png_voidp mem_ptr,png_malloc_ptr malloc_fn,png_free_ptr free_fn)260*a67afe4dSAndroid Build Coastguard Worker png_set_mem_fn(png_structrp png_ptr, png_voidp mem_ptr, png_malloc_ptr
261*a67afe4dSAndroid Build Coastguard Worker malloc_fn, png_free_ptr free_fn)
262*a67afe4dSAndroid Build Coastguard Worker {
263*a67afe4dSAndroid Build Coastguard Worker if (png_ptr != NULL)
264*a67afe4dSAndroid Build Coastguard Worker {
265*a67afe4dSAndroid Build Coastguard Worker png_ptr->mem_ptr = mem_ptr;
266*a67afe4dSAndroid Build Coastguard Worker png_ptr->malloc_fn = malloc_fn;
267*a67afe4dSAndroid Build Coastguard Worker png_ptr->free_fn = free_fn;
268*a67afe4dSAndroid Build Coastguard Worker }
269*a67afe4dSAndroid Build Coastguard Worker }
270*a67afe4dSAndroid Build Coastguard Worker
271*a67afe4dSAndroid Build Coastguard Worker /* This function returns a pointer to the mem_ptr associated with the user
272*a67afe4dSAndroid Build Coastguard Worker * functions. The application should free any memory associated with this
273*a67afe4dSAndroid Build Coastguard Worker * pointer before png_write_destroy and png_read_destroy are called.
274*a67afe4dSAndroid Build Coastguard Worker */
275*a67afe4dSAndroid Build Coastguard Worker png_voidp PNGAPI
png_get_mem_ptr(png_const_structrp png_ptr)276*a67afe4dSAndroid Build Coastguard Worker png_get_mem_ptr(png_const_structrp png_ptr)
277*a67afe4dSAndroid Build Coastguard Worker {
278*a67afe4dSAndroid Build Coastguard Worker if (png_ptr == NULL)
279*a67afe4dSAndroid Build Coastguard Worker return NULL;
280*a67afe4dSAndroid Build Coastguard Worker
281*a67afe4dSAndroid Build Coastguard Worker return png_ptr->mem_ptr;
282*a67afe4dSAndroid Build Coastguard Worker }
283*a67afe4dSAndroid Build Coastguard Worker #endif /* USER_MEM */
284*a67afe4dSAndroid Build Coastguard Worker #endif /* READ || WRITE */
285