Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | |
michael@0 | 2 | /* pngwio.c - functions for data output |
michael@0 | 3 | * |
michael@0 | 4 | * Last changed in libpng 1.6.9 [February 6, 2014] |
michael@0 | 5 | * Copyright (c) 1998-2014 Glenn Randers-Pehrson |
michael@0 | 6 | * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
michael@0 | 7 | * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
michael@0 | 8 | * |
michael@0 | 9 | * This code is released under the libpng license. |
michael@0 | 10 | * For conditions of distribution and use, see the disclaimer |
michael@0 | 11 | * and license in png.h |
michael@0 | 12 | * |
michael@0 | 13 | * This file provides a location for all output. Users who need |
michael@0 | 14 | * special handling are expected to write functions that have the same |
michael@0 | 15 | * arguments as these and perform similar functions, but that possibly |
michael@0 | 16 | * use different output methods. Note that you shouldn't change these |
michael@0 | 17 | * functions, but rather write replacement functions and then change |
michael@0 | 18 | * them at run time with png_set_write_fn(...). |
michael@0 | 19 | */ |
michael@0 | 20 | |
michael@0 | 21 | #include "pngpriv.h" |
michael@0 | 22 | |
michael@0 | 23 | #ifdef PNG_WRITE_SUPPORTED |
michael@0 | 24 | |
michael@0 | 25 | /* Write the data to whatever output you are using. The default routine |
michael@0 | 26 | * writes to a file pointer. Note that this routine sometimes gets called |
michael@0 | 27 | * with very small lengths, so you should implement some kind of simple |
michael@0 | 28 | * buffering if you are using unbuffered writes. This should never be asked |
michael@0 | 29 | * to write more than 64K on a 16 bit machine. |
michael@0 | 30 | */ |
michael@0 | 31 | |
michael@0 | 32 | void /* PRIVATE */ |
michael@0 | 33 | png_write_data(png_structrp png_ptr, png_const_bytep data, png_size_t length) |
michael@0 | 34 | { |
michael@0 | 35 | /* NOTE: write_data_fn must not change the buffer! */ |
michael@0 | 36 | if (png_ptr->write_data_fn != NULL ) |
michael@0 | 37 | (*(png_ptr->write_data_fn))(png_ptr, png_constcast(png_bytep,data), |
michael@0 | 38 | length); |
michael@0 | 39 | |
michael@0 | 40 | else |
michael@0 | 41 | png_error(png_ptr, "Call to NULL write function"); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | #ifdef PNG_STDIO_SUPPORTED |
michael@0 | 45 | /* This is the function that does the actual writing of data. If you are |
michael@0 | 46 | * not writing to a standard C stream, you should create a replacement |
michael@0 | 47 | * write_data function and use it at run time with png_set_write_fn(), rather |
michael@0 | 48 | * than changing the library. |
michael@0 | 49 | */ |
michael@0 | 50 | void PNGCBAPI |
michael@0 | 51 | png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) |
michael@0 | 52 | { |
michael@0 | 53 | png_size_t check; |
michael@0 | 54 | |
michael@0 | 55 | if (png_ptr == NULL) |
michael@0 | 56 | return; |
michael@0 | 57 | |
michael@0 | 58 | check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr)); |
michael@0 | 59 | |
michael@0 | 60 | if (check != length) |
michael@0 | 61 | png_error(png_ptr, "Write Error"); |
michael@0 | 62 | } |
michael@0 | 63 | #endif |
michael@0 | 64 | |
michael@0 | 65 | /* This function is called to output any data pending writing (normally |
michael@0 | 66 | * to disk). After png_flush is called, there should be no data pending |
michael@0 | 67 | * writing in any buffers. |
michael@0 | 68 | */ |
michael@0 | 69 | #ifdef PNG_WRITE_FLUSH_SUPPORTED |
michael@0 | 70 | void /* PRIVATE */ |
michael@0 | 71 | png_flush(png_structrp png_ptr) |
michael@0 | 72 | { |
michael@0 | 73 | if (png_ptr->output_flush_fn != NULL) |
michael@0 | 74 | (*(png_ptr->output_flush_fn))(png_ptr); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | # ifdef PNG_STDIO_SUPPORTED |
michael@0 | 78 | void PNGCBAPI |
michael@0 | 79 | png_default_flush(png_structp png_ptr) |
michael@0 | 80 | { |
michael@0 | 81 | png_FILE_p io_ptr; |
michael@0 | 82 | |
michael@0 | 83 | if (png_ptr == NULL) |
michael@0 | 84 | return; |
michael@0 | 85 | |
michael@0 | 86 | io_ptr = png_voidcast(png_FILE_p, (png_ptr->io_ptr)); |
michael@0 | 87 | fflush(io_ptr); |
michael@0 | 88 | } |
michael@0 | 89 | # endif |
michael@0 | 90 | #endif |
michael@0 | 91 | |
michael@0 | 92 | /* This function allows the application to supply new output functions for |
michael@0 | 93 | * libpng if standard C streams aren't being used. |
michael@0 | 94 | * |
michael@0 | 95 | * This function takes as its arguments: |
michael@0 | 96 | * png_ptr - pointer to a png output data structure |
michael@0 | 97 | * io_ptr - pointer to user supplied structure containing info about |
michael@0 | 98 | * the output functions. May be NULL. |
michael@0 | 99 | * write_data_fn - pointer to a new output function that takes as its |
michael@0 | 100 | * arguments a pointer to a png_struct, a pointer to |
michael@0 | 101 | * data to be written, and a 32-bit unsigned int that is |
michael@0 | 102 | * the number of bytes to be written. The new write |
michael@0 | 103 | * function should call png_error(png_ptr, "Error msg") |
michael@0 | 104 | * to exit and output any fatal error messages. May be |
michael@0 | 105 | * NULL, in which case libpng's default function will |
michael@0 | 106 | * be used. |
michael@0 | 107 | * flush_data_fn - pointer to a new flush function that takes as its |
michael@0 | 108 | * arguments a pointer to a png_struct. After a call to |
michael@0 | 109 | * the flush function, there should be no data in any buffers |
michael@0 | 110 | * or pending transmission. If the output method doesn't do |
michael@0 | 111 | * any buffering of output, a function prototype must still be |
michael@0 | 112 | * supplied although it doesn't have to do anything. If |
michael@0 | 113 | * PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile |
michael@0 | 114 | * time, output_flush_fn will be ignored, although it must be |
michael@0 | 115 | * supplied for compatibility. May be NULL, in which case |
michael@0 | 116 | * libpng's default function will be used, if |
michael@0 | 117 | * PNG_WRITE_FLUSH_SUPPORTED is defined. This is not |
michael@0 | 118 | * a good idea if io_ptr does not point to a standard |
michael@0 | 119 | * *FILE structure. |
michael@0 | 120 | */ |
michael@0 | 121 | void PNGAPI |
michael@0 | 122 | png_set_write_fn(png_structrp png_ptr, png_voidp io_ptr, |
michael@0 | 123 | png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn) |
michael@0 | 124 | { |
michael@0 | 125 | if (png_ptr == NULL) |
michael@0 | 126 | return; |
michael@0 | 127 | |
michael@0 | 128 | png_ptr->io_ptr = io_ptr; |
michael@0 | 129 | |
michael@0 | 130 | #ifdef PNG_STDIO_SUPPORTED |
michael@0 | 131 | if (write_data_fn != NULL) |
michael@0 | 132 | png_ptr->write_data_fn = write_data_fn; |
michael@0 | 133 | |
michael@0 | 134 | else |
michael@0 | 135 | png_ptr->write_data_fn = png_default_write_data; |
michael@0 | 136 | #else |
michael@0 | 137 | png_ptr->write_data_fn = write_data_fn; |
michael@0 | 138 | #endif |
michael@0 | 139 | |
michael@0 | 140 | #ifdef PNG_WRITE_FLUSH_SUPPORTED |
michael@0 | 141 | # ifdef PNG_STDIO_SUPPORTED |
michael@0 | 142 | |
michael@0 | 143 | if (output_flush_fn != NULL) |
michael@0 | 144 | png_ptr->output_flush_fn = output_flush_fn; |
michael@0 | 145 | |
michael@0 | 146 | else |
michael@0 | 147 | png_ptr->output_flush_fn = png_default_flush; |
michael@0 | 148 | |
michael@0 | 149 | # else |
michael@0 | 150 | png_ptr->output_flush_fn = output_flush_fn; |
michael@0 | 151 | # endif |
michael@0 | 152 | #else |
michael@0 | 153 | PNG_UNUSED(output_flush_fn) |
michael@0 | 154 | #endif /* PNG_WRITE_FLUSH_SUPPORTED */ |
michael@0 | 155 | |
michael@0 | 156 | #ifdef PNG_READ_SUPPORTED |
michael@0 | 157 | /* It is an error to read while writing a png file */ |
michael@0 | 158 | if (png_ptr->read_data_fn != NULL) |
michael@0 | 159 | { |
michael@0 | 160 | png_ptr->read_data_fn = NULL; |
michael@0 | 161 | |
michael@0 | 162 | png_warning(png_ptr, |
michael@0 | 163 | "Can't set both read_data_fn and write_data_fn in the" |
michael@0 | 164 | " same structure"); |
michael@0 | 165 | } |
michael@0 | 166 | #endif |
michael@0 | 167 | } |
michael@0 | 168 | #endif /* PNG_WRITE_SUPPORTED */ |