• Home
  • Raw
  • Download

Lines Matching refs:file

832 struct file  struct
860 FILE * file; /* Original PNG file */ argument
901 void (*alloc)(struct file*,int idat); argument
948 emit_error(struct file *file, int code, const char *what) in emit_error() argument
963 err = file->read_errno; in emit_error()
966 err = file->write_errno; in emit_error()
969 err = file->read_errno; in emit_error()
971 err = file->write_errno; in emit_error()
977 fprintf(stderr, "%s: %s %s [%s]\n", file->file_name, reason, what, in emit_error()
981 fprintf(stderr, "%s: %s %s\n", file->file_name, reason, what); in emit_error()
988 file_end(struct file *file) in file_end() argument
995 if (file->idat != NULL) in file_end()
996 IDAT_end(&file->idat); in file_end()
998 if (file->chunk != NULL) in file_end()
999 chunk_end(&file->chunk); in file_end()
1001 rc = file->status_code; in file_end()
1003 if (file->file != NULL) in file_end()
1004 (void)fclose(file->file); in file_end()
1006 if (file->out != NULL) in file_end()
1011 if (ferror(file->out) | fflush(file->out) | fclose(file->out)) in file_end()
1013 perror(file->out_name); in file_end()
1014 emit_error(file, READ_ERROR_CODE, "output write error"); in file_end()
1020 file->global->status_code |= rc; in file_end()
1022 CLEAR(*file); in file_end()
1028 file_init(struct file *file, struct global *global, const char *file_name, in file_init() argument
1029 const char *out_name, void *alloc_ptr, void (*alloc)(struct file*,int)) in file_init() argument
1035 CLEAR(*file); in file_init()
1036 file->global = global; in file_init()
1038 file->file_name = file_name; in file_init()
1039 file->out_name = out_name; in file_init()
1040 file->status_code = 0; in file_init()
1041 file->read_errno = 0; in file_init()
1042 file->write_errno = 0; in file_init()
1044 file->file = NULL; in file_init()
1045 file->out = NULL; in file_init()
1048 file->read_count = 0; in file_init()
1049 file->state = STATE_SIGNATURE; in file_init()
1051 file->chunk = NULL; in file_init()
1052 file->idat = NULL; in file_init()
1054 file->alloc_ptr = alloc_ptr; in file_init()
1055 file->alloc = alloc; in file_init()
1059 file->file = fopen(file_name, "rb"); in file_init()
1061 if (file->file == NULL) in file_init()
1063 file->read_errno = errno; in file_init()
1064 file->status_code |= FILE_ERROR; in file_init()
1072 file->out = fopen(out_name, "wb"); in file_init()
1074 if (file->out == NULL) in file_init()
1076 file->write_errno = errno; in file_init()
1077 file->status_code |= WRITE_ERROR; in file_init()
1087 log_error(struct file *file, int code, const char *what) in log_error() argument
1090 if (file->global->errors) in log_error()
1091 emit_error(file, code, what); in log_error()
1126 static png_uint_32 current_type(struct file *file, int code);
1129 stop(struct file *file, int code, const char *what) in stop() argument
1134 log_error(file, code, what); in stop()
1149 if (file->global->quiet < 2) /* need two quiets to stop this. */ in stop()
1153 if (file->chunk != NULL) in stop()
1154 type = current_type(file, code); /* Gropes in struct chunk and IDAT */ in stop()
1157 type = file->type; in stop()
1165 printf(" ERR %.2x %s ", file->status_code, strcode(code)); in stop()
1169 emit_string(strerror(file->read_errno), stdout); in stop()
1171 emit_string(strerror(file->write_errno), stdout); in stop()
1175 fputs(file->file_name, stdout); in stop()
1179 file->status_code |= FILE_ERROR; in stop()
1180 longjmp(file->jmpbuf, code); in stop()
1184 stop_invalid(struct file *file, const char *what) in stop_invalid() argument
1186 stop(file, INVALID_ERROR_CODE, what); in stop_invalid()
1190 type_message(struct file *file, png_uint_32 type, const char *what) in type_message() argument
1193 if (file->global->errors) in type_message()
1195 fputs(file->file_name, stderr); in type_message()
1208 file_getpos(struct file *file, fpos_t *pos) in file_getpos() argument
1210 if (fgetpos(file->file, pos)) in file_getpos()
1213 perror(file->file_name); in file_getpos()
1214 stop(file, READ_ERROR_CODE, "fgetpos"); in file_getpos()
1219 file_setpos(struct file *file, const fpos_t *pos) in file_setpos() argument
1221 if (fsetpos(file->file, pos)) in file_setpos()
1223 perror(file->file_name); in file_setpos()
1224 stop(file, READ_ERROR_CODE, "fsetpos"); in file_setpos()
1229 getpos(struct file *file) in getpos() argument
1235 file_getpos(file, &file->data_pos); in getpos()
1244 read_byte(struct file *file) in read_byte() argument
1246 int ch = getc(file->file); in read_byte()
1250 ++(file->read_count); in read_byte()
1256 file->status_code |= INTERNAL_ERROR; in read_byte()
1257 file->read_errno = ERANGE; /* out of range character */ in read_byte()
1260 emit_error(file, UNEXPECTED_ERROR_CODE, "file read"); in read_byte()
1267 return read_byte(file); in read_byte()
1276 if (ferror(file->file)) in read_byte()
1277 file->read_errno = errno; in read_byte()
1279 else if (feof(file->file)) in read_byte()
1280 file->read_errno = 0; /* I.e. a regular EOF, no error */ in read_byte()
1283 file->read_errno = EDOM; in read_byte()
1290 file->status_code |= TRUNCATED; in read_byte()
1295 reread_byte(struct file *file) in reread_byte() argument
1300 int ch = getc(file->file); in reread_byte()
1303 file->read_errno = errno; in reread_byte()
1306 stop(file, UNEXPECTED_ERROR_CODE, "reread"); in reread_byte()
1312 reread_4(struct file *file) in reread_4() argument
1319 result = (result << 8) + reread_byte(file); in reread_4()
1325 skip_12(struct file *file) in skip_12() argument
1331 if (fseek(file->file, 12, SEEK_CUR) != 0) in skip_12()
1334 file->read_errno = errno; in skip_12()
1336 stop(file, UNEXPECTED_ERROR_CODE, "reskip"); in skip_12()
1341 write_byte(struct file *file, int b) in write_byte() argument
1347 if (file->out != NULL) in write_byte()
1349 if (putc(b, file->out) != b) in write_byte()
1351 file->write_errno = errno; in write_byte()
1352 file->status_code |= WRITE_ERROR; in write_byte()
1353 stop(file, WRITE_ERROR_CODE, "write byte"); in write_byte()
1357 ++(file->write_count); in write_byte()
1362 read_4(struct file *file, png_uint_32 *pu) in read_4() argument
1372 int ch = read_byte(file); in read_4()
1386 crc_read_many(struct file *file, png_uint_32 length) in crc_read_many() argument
1393 png_uint_32 crc = file->crc; in crc_read_many()
1397 int ch = read_byte(file); in crc_read_many()
1406 file->crc = crc; in crc_read_many()
1413 calc_image_size(struct file *file) in calc_image_size() argument
1418 png_uint_16 pd = file->bit_depth; in calc_image_size()
1420 switch (file->color_type) in calc_image_size()
1423 stop_invalid(file, "IHDR: colour type"); in calc_image_size()
1426 stop_invalid(file, "IHDR: bit depth"); in calc_image_size()
1460 if (file->width < 1 || file->width > 0x7fffffff) in calc_image_size()
1461 stop_invalid(file, "IHDR: width"); in calc_image_size()
1463 else if (file->height < 1 || file->height > 0x7fffffff) in calc_image_size()
1464 stop_invalid(file, "IHDR: height"); in calc_image_size()
1466 else if (file->compression_method != 0) in calc_image_size()
1467 stop_invalid(file, "IHDR: compression method"); in calc_image_size()
1469 else if (file->filter_method != 0) in calc_image_size()
1470 stop_invalid(file, "IHDR: filter method"); in calc_image_size()
1472 else switch (file->interlace_method) in calc_image_size()
1485 png_uint_32 pw = PNG_PASS_COLS(file->width, pass); in calc_image_size()
1499 image_digits = uarb_mult32(file->image_bytes, image_digits, in calc_image_size()
1501 PNG_PASS_ROWS(file->height, pass)); in calc_image_size()
1505 file->image_digits = image_digits; in calc_image_size()
1516 row_width, uarb_set(row_width, file->width), pd); in calc_image_size()
1521 file->image_digits = uarb_mult32(file->image_bytes, 0, in calc_image_size()
1522 row_bytes, digits, file->height); in calc_image_size()
1527 stop_invalid(file, "IHDR: interlace method"); in calc_image_size()
1530 assert(file->image_digits >= 1 && file->image_digits <= 5); in calc_image_size()
1542 struct file * file; member
1569 type_message(chunk->file, chunk->chunk_type, message); in chunk_message()
1582 chunk_init(struct chunk * const chunk, struct file * const file) in chunk_init() argument
1590 assert(file->chunk == NULL); in chunk_init()
1594 chunk->file = file; in chunk_init()
1595 chunk->global = file->global; in chunk_init()
1597 chunk->chunk_data_pos = file->data_pos; in chunk_init()
1598 chunk->chunk_length = file->length; in chunk_init()
1599 chunk->chunk_type = file->type; in chunk_init()
1607 file->chunk = chunk; in chunk_init()
1611 current_type(struct file *file, int code) in current_type() argument
1619 if (file->chunk != NULL) in current_type()
1621 png_uint_32 type = file->chunk->chunk_type; in current_type()
1628 file->write_count == 8) in current_type()
1635 return file->type; in current_type()
1645 chunk->file->read_count = 8; in setpos()
1646 file_setpos(chunk->file, &chunk->chunk_data_pos); in setpos()
1660 static int zlib_check(struct file *file, png_uint_32 offset);
1663 process_zTXt_iCCP(struct file *file) in process_zTXt_iCCP() argument
1668 struct chunk *chunk = file->chunk; in process_zTXt_iCCP()
1672 assert(chunk != NULL && file->idat == NULL); in process_zTXt_iCCP()
1680 if (reread_byte(file) == 0) /* keyword null terminator */ in process_zTXt_iCCP()
1684 (void)reread_byte(file); /* compression method */ in process_zTXt_iCCP()
1685 return zlib_check(file, index); in process_zTXt_iCCP()
1694 process_iTXt(struct file *file) in process_iTXt() argument
1697 struct chunk *chunk = file->chunk; in process_iTXt()
1701 assert(chunk != NULL && file->idat == NULL); in process_iTXt()
1709 if (reread_byte(file) == 0) /* keyword null terminator */ in process_iTXt()
1713 if (reread_byte(file) == 0) /* uncompressed text */ in process_iTXt()
1718 (void)reread_byte(file); /* compression method */ in process_iTXt()
1725 if (reread_byte(file) == 0) /* terminator */ in process_iTXt()
1732 if (reread_byte(file) == 0) /* terminator */ in process_iTXt()
1733 return zlib_check(file, index); in process_iTXt()
1743 log_error(file, INVALID_ERROR_CODE, "iTXt chunk length"); in process_iTXt()
1752 struct file * file; member
1774 struct file *file = idat->file; in IDAT_end() local
1780 assert(file->chunk != NULL); in IDAT_end()
1781 chunk_end(&file->chunk); in IDAT_end()
1787 file->state = STATE_CHUNKS; in IDAT_end()
1791 IDAT_init(struct IDAT * const idat, struct file * const file) in IDAT_init() argument
1799 assert(file->chunk == NULL); in IDAT_init()
1800 assert(file->idat == NULL); in IDAT_init()
1804 idat->file = file; in IDAT_init()
1805 idat->global = file->global; in IDAT_init()
1816 file->alloc(file, 0/*chunk*/); in IDAT_init()
1817 assert(file->chunk != NULL); in IDAT_init()
1822 file->idat = idat; in IDAT_init()
1907 process_IDAT(struct file *file) in process_IDAT() argument
1926 assert(file->idat != NULL && file->chunk != NULL); in process_IDAT()
1937 list = file->idat->idat_list_tail; in process_IDAT()
1944 stop(file, READ_ERROR_CODE, "out of memory"); in process_IDAT()
1948 file->idat->idat_list_tail = list; in process_IDAT()
1952 list->lengths[(list->count)++] = file->chunk->chunk_length; in process_IDAT()
1957 if (file->type == png_IDAT) in process_IDAT()
1965 setpos(file->chunk); in process_IDAT()
1967 if (zlib_check(file, 0)) in process_IDAT()
1975 cmp = uarb_cmp(file->image_bytes, file->image_digits, in process_IDAT()
1976 file->chunk->uncompressed_bytes, file->chunk->uncompressed_digits); in process_IDAT()
1979 type_message(file, png_IDAT, "extra uncompressed data"); in process_IDAT()
1982 stop(file, LIBPNG_ERROR_CODE, "IDAT: uncompressed data too small"); in process_IDAT()
1988 setpos(file->chunk); in process_IDAT()
1990 idat = file->idat; in process_IDAT()
1997 file->chunk->chunk_length = rechunk_length(idat, 1/*start*/); in process_IDAT()
2000 file->state = STATE_IDAT; in process_IDAT()
2006 stop(file, ZLIB_ERROR_CODE, "could not uncompress IDAT"); in process_IDAT()
2015 struct file * file; member
2084 fputs(zlib->file->file_name, stderr); in zlib_message()
2128 fputs(zlib->file->file_name, stdout); in zlib_end()
2152 fputs(zlib->file->file_name, stdout); in zlib_end()
2203 zlib->file = chunk->file; in zlib_init()
2285 struct file *file = zlib->file; in zlib_advance() local
2293 png_byte bIn = reread_byte(file); in zlib_advance()
2525 skip_12(zlib->file); in zlib_run()
2607 zlib_check(struct file *file, png_uint_32 offset) in zlib_check() argument
2625 file_getpos(file, &start_pos); in zlib_check()
2628 if (zlib_init(&zlib, file->idat, file->chunk, 0/*window bits*/, offset)) in zlib_check()
2639 file->status_code |= TOO_FAR_BACK; in zlib_check()
2695 file_setpos(file, &start_pos); in zlib_check()
2782 static void read_chunk(struct file *file);
2784 process_chunk(struct file *file, png_uint_32 file_crc, png_uint_32 next_length, in process_chunk() argument
2794 png_uint_32 type = file->type; in process_chunk()
2796 if (file->global->verbose > 1) in process_chunk()
2799 type_name(file->type, stderr); in process_chunk()
2800 fprintf(stderr, " %lu 0x%.8x 0x%.8x\n", (unsigned long)file->length, in process_chunk()
2801 file->crc ^ 0xffffffff, file_crc); in process_chunk()
2808 if ((file->crc ^ 0xffffffff) != file_crc) in process_chunk()
2815 file->status_code |= CRC_ERROR; in process_chunk()
2818 if (file->global->skip != SKIP_BAD_CRC) in process_chunk()
2819 type_message(file, type, "bad CRC"); in process_chunk()
2823 stop(file, READ_ERROR_CODE, "bad CRC in critical chunk"); in process_chunk()
2827 type_message(file, type, "skipped: bad CRC"); in process_chunk()
2838 if (skip_chunk_type(file->global, type)) in process_chunk()
2847 file->alloc(file, 0/*chunk*/); in process_chunk()
2849 else if (file->idat == NULL) in process_chunk()
2850 file->alloc(file, 1/*IDAT*/); in process_chunk()
2855 assert(file->chunk != NULL); in process_chunk()
2856 assert(file->chunk->chunk_type == png_IDAT); in process_chunk()
2857 file->chunk->chunk_length = file->length; in process_chunk()
2865 file->length = next_length; in process_chunk()
2866 file->type = next_type; in process_chunk()
2867 getpos(file); in process_chunk()
2873 file->chunk->rewrite_length = 0; in process_chunk()
2874 file->chunk->rewrite_offset = 0; in process_chunk()
2886 struct chunk *chunk = file->chunk; in process_chunk()
2889 stop_invalid(file, "IHDR length"); in process_chunk()
2893 file->width = reread_4(file); in process_chunk()
2894 file->height = reread_4(file); in process_chunk()
2895 file->bit_depth = reread_byte(file); in process_chunk()
2896 file->color_type = reread_byte(file); in process_chunk()
2897 file->compression_method = reread_byte(file); in process_chunk()
2898 file->filter_method = reread_byte(file); in process_chunk()
2899 file->interlace_method = reread_byte(file); in process_chunk()
2904 calc_image_size(file); in process_chunk()
2910 if (process_zTXt_iCCP(file)) in process_chunk()
2912 chunk_end(&file->chunk); in process_chunk()
2913 file_setpos(file, &file->data_pos); in process_chunk()
2917 if (process_iTXt(file)) in process_chunk()
2919 chunk_end(&file->chunk); in process_chunk()
2920 file_setpos(file, &file->data_pos); in process_chunk()
2924 if (process_IDAT(file)) in process_chunk()
2938 read_chunk(file); in process_chunk()
2945 file->length = next_length; in process_chunk()
2946 file->type = next_type; in process_chunk()
2947 getpos(file); in process_chunk()
2948 read_chunk(file); in process_chunk()
2964 sync_stream(struct file *file) in sync_stream() argument
2971 file->status_code |= STREAM_ERROR; in sync_stream()
2973 if (file->global->verbose) in sync_stream()
2976 type_name(file->type, stderr); in sync_stream()
2981 file_setpos(file, &file->data_pos); in sync_stream()
2982 file->read_count = 8; in sync_stream()
2984 if (read_4(file, &file_crc) == 4) /* else completely truncated */ in sync_stream()
2992 png_uint_32 type = file->type; in sync_stream()
3008 file->length = length; in sync_stream()
3009 process_chunk(file, file_crc, 0, 0); in sync_stream()
3018 ch = read_byte(file); in sync_stream()
3038 file->read_count -= 8; in sync_stream()
3039 process_chunk(file, file_crc, next_length, next_type); in sync_stream()
3059 ch = read_byte(file); in sync_stream()
3078 stop(file, READ_ERROR_CODE, "damaged PNG stream"); in sync_stream()
3082 read_chunk(struct file *file) in read_chunk() argument
3096 png_uint_32 length = file->length; in read_chunk()
3097 png_uint_32 type = file->type; in read_chunk()
3103 stop(file, UNEXPECTED_ERROR_CODE, "read beyond IEND"); in read_chunk()
3105 if (file->global->verbose > 2) in read_chunk()
3116 file->crc = crc_init_4(type); in read_chunk()
3117 if (crc_read_many(file, length)) /* else it was truncated */ in read_chunk()
3120 unsigned int nread = read_4(file, &file_crc); in read_chunk()
3128 nread += read_4(file, &next_length); in read_chunk()
3133 nread += read_4(file, &next_type); in read_chunk()
3140 file->read_count -= 8; in read_chunk()
3141 process_chunk(file, file_crc, next_length, next_type); in read_chunk()
3149 process_chunk(file, file_crc, 0, 0); in read_chunk()
3162 sync_stream(file); in read_chunk()
3166 static struct file *get_control(png_const_structrp png_ptr);
3177 struct file *file = get_control(png_ptr); in warning_handler() local
3179 if (file->global->warnings) in warning_handler()
3180 emit_error(file, LIBPNG_WARNING_CODE, message); in warning_handler()
3190 struct file *file = get_control(png_ptr); in read_callback() local
3196 stop(file, UNEXPECTED_ERROR_CODE, "read callback for 0 bytes"); in read_callback()
3203 if (file->read_count < 8) in read_callback()
3205 assert(file->read_count == 0); in read_callback()
3206 assert((file->status_code & TRUNCATED) == 0); in read_callback()
3208 (void)read_4(file, &file->length); in read_callback()
3210 if (file->read_count == 4) in read_callback()
3211 (void)read_4(file, &file->type); in read_callback()
3213 if (file->read_count < 8) in read_callback()
3215 assert((file->status_code & TRUNCATED) != 0); in read_callback()
3216 stop(file, READ_ERROR_CODE, "not a PNG (too short)"); in read_callback()
3219 if (file->state == STATE_SIGNATURE) in read_callback()
3221 if (file->length != sig1 || file->type != sig2) in read_callback()
3222 stop(file, LIBPNG_ERROR_CODE, "not a PNG (signature)"); in read_callback()
3227 file->write_count = 0; in read_callback()
3232 assert(file->state == STATE_CHUNKS); in read_callback()
3237 if (file->length != 13 || file->type != png_IHDR) in read_callback()
3238 stop(file, LIBPNG_ERROR_CODE, "not a PNG (IHDR)"); in read_callback()
3241 getpos(file); in read_callback()
3248 chunk = file->chunk; in read_callback()
3261 length = file->length; in read_callback()
3262 type = file->type; in read_callback()
3279 if (file->state != STATE_SIGNATURE && chunk == NULL) in read_callback()
3281 assert(file->read_count == 8); in read_callback()
3282 assert(file->idat == NULL); in read_callback()
3283 read_chunk(file); in read_callback()
3284 chunk = file->chunk; in read_callback()
3292 file->write_count = 0; in read_callback()
3299 switch (file->write_count) in read_callback()
3316 if (file->state == STATE_SIGNATURE) in read_callback()
3323 file->read_count = 0; /* Forces a header read */ in read_callback()
3324 file->state = STATE_CHUNKS; /* IHDR: checked above */ in read_callback()
3340 if (file->state != STATE_IDAT && length > 0) in read_callback()
3351 switch (file->write_count - length) in read_callback()
3360 if (file->state == STATE_IDAT) in read_callback()
3362 struct IDAT *idat = file->idat; in read_callback()
3392 stop(file, UNEXPECTED_ERROR_CODE, in read_callback()
3406 skip_12(file); in read_callback()
3417 b = reread_byte(file); in read_callback()
3452 if (file->global->verbose > 2) in read_callback()
3467 if (file->state == STATE_IDAT && in read_callback()
3468 (file->idat->idat_index < file->idat->idat_length || in read_callback()
3469 1+file->idat->idat_count < file->idat->idat_cur->count || in read_callback()
3470 file->idat->idat_cur != file->idat->idat_list_tail)) in read_callback()
3476 rechunk_length(file->idat, 0/*end*/); in read_callback()
3478 file->write_count = 0; /* for the new chunk */ in read_callback()
3479 --(file->write_count); /* fake out the increment below */ in read_callback()
3488 stop(file, UNEXPECTED_ERROR_CODE, "pending rewrite"); in read_callback()
3494 file->read_count = 8; in read_callback()
3495 file_setpos(file, &file->data_pos); in read_callback()
3497 if (file->idat == NULL) in read_callback()
3498 chunk_end(&file->chunk); in read_callback()
3501 IDAT_end(&file->idat); in read_callback()
3515 write_byte(file, (png_byte)b); /* increments chunk_write */ in read_callback()
3525 struct file file; member
3533 return file_end(&control->file); in control_end()
3536 static struct file *
3544 return &control->file; in get_control()
3548 allocate(struct file *file, int allocate_idat) in allocate() argument
3550 struct control *control = voidcast(struct control*, file->alloc_ptr); in allocate()
3554 assert(file->idat == NULL); in allocate()
3555 IDAT_init(&control->idat, file); in allocate()
3560 assert(file->chunk == NULL); in allocate()
3561 chunk_init(&control->chunk, file); in allocate()
3572 return file_init(&control->file, global, file_name, out_name, control, in control_init()
3592 log_error(&control->file, LIBPNG_ERROR_CODE, "OOM allocating png_struct"); in read_png()
3593 control->file.status_code |= INTERNAL_ERROR; in read_png()
3597 rc = setjmp(control->file.jmpbuf); in read_png()
3616 if (control->file.global->verbose) in read_png()
3640 if (control->file.global->verbose) in read_png()