Lines Matching full:chunk

92 /* Chunk tags (copied from pngpriv.h) */
97 /* Constants for known chunk types. */
130 /* Is the chunk critical? */
131 #define CRITICAL(chunk) (((chunk) & PNG_U32(32,0,0,0)) == 0) argument
134 #define SAFE_TO_COPY(chunk) (((chunk) & PNG_U32(0,0,0,32)) != 0) argument
544 * the parser below where length+chunk-name is read and chunk-name used to in crc_init_4()
557 /* Bit whacking approach to chunk name validation that is intended to avoid in chunk_type_valid()
739 /* Return true if this chunk is to be skipped according to the --strip in skip_chunk_type()
795 * whether the safe-to-copy bit is set in the chunk type. in skip_chunk_type()
812 struct chunk;
846 /* PROTECTED CHUNK SPECIFIC VARIABLES: USED BY CHUNK CODE */
848 * and data position of the *next* chunk or, right at the start, the
851 * When a chunk control structure is instantiated these values are copied
853 * chunk.
855 fpos_t data_pos; /* Position of first byte of chunk data */
858 png_uint_32 crc; /* Running chunk CRC (used by read_chunk) */
861 * reset by the chunk handling code. They record the total number of bytes
862 * read or written for the chunk, including the header (length,type) bytes.
864 png_uint_32 read_count; /* Count of bytes read (in the chunk) */
865 png_uint_32 write_count; /* Count of bytes written (in the chunk) */
874 struct chunk * chunk; member
877 /* Interface to allocate a new chunk or IDAT control structure. The result
884 /* idat: allocate IDAT not chunk */
966 static void chunk_end(struct chunk **);
974 /* If either of the chunk pointers are set end them here, the IDAT structure in file_end()
975 * must be deallocated first as it may deallocate the chunk structure. in file_end()
980 if (file->chunk != NULL) in file_end()
981 chunk_end(&file->chunk); in file_end()
1041 file->chunk = NULL; in file_init()
1087 /* In fact because chunk::chunk_type is validated prior to any call to this in type_char()
1126 /* The chunk being read is typically identified by file->chunk or, if this is in stop()
1143 if (file->chunk != NULL) in stop()
1144 type = current_type(file, code); /* Gropes in struct chunk and IDAT */ in stop()
1153 fputs("HEAD", stdout); /* not a registered chunk! */ in stop()
1181 /* Error message for a chunk; the chunk name comes from 'type' */ in type_message()
1221 * setpos() function is chunk specific because it uses the copy of the in getpos()
1222 * position for the specific chunk. in getpos()
1316 /* Skip exactly 12 bytes in the input stream - used to skip a CRC and chunk in skip_12()
1524 /* PER-CHUNK CONTROL STRUCTURE
1525 * This structure is instantiated for each chunk, except for the IDAT chunks
1526 * where one chunk control structure is used for the whole of a single stream of
1529 struct chunk struct
1541 /* PUBLIC PER-CHUNK INFORMATION: USED BY CHUNK READ CODE */
1545 fpos_t chunk_data_pos; /* Position of first byte of chunk data */ argument
1549 /* PUBLIC PER-CHUNK INFORMATION: FOR THE CHUNK WRITE CODE */
1557 chunk_message(struct chunk *chunk, const char *message) in chunk_message() argument
1559 type_message(chunk->file, chunk->chunk_type, message); in chunk_message()
1563 chunk_end(struct chunk **chunk_var) in chunk_end()
1565 struct chunk *chunk = *chunk_var; in chunk_end() local
1568 CLEAR(*chunk); in chunk_end()
1572 chunk_init(struct chunk * const chunk, struct file * const file) in chunk_init() argument
1573 /* When a chunk is initialized the file length/type/pos are copied into the in chunk_init()
1574 * corresponding chunk fields and the new chunk is registered in the file in chunk_init()
1575 * structure. There can only be one chunk at a time. in chunk_init()
1580 assert(file->chunk == NULL); in chunk_init()
1582 CLEAR(*chunk); in chunk_init()
1584 chunk->file = file; in chunk_init()
1585 chunk->global = file->global; in chunk_init()
1587 chunk->chunk_data_pos = file->data_pos; in chunk_init()
1588 chunk->chunk_length = file->length; in chunk_init()
1589 chunk->chunk_type = file->type; in chunk_init()
1592 * that is used to check the compressed data in a chunk.) in chunk_init()
1594 chunk->uncompressed_digits = 0; in chunk_init()
1595 chunk->compressed_digits = 0; in chunk_init()
1597 file->chunk = chunk; in chunk_init()
1602 /* Guess the actual chunk type that causes a stop() */ in current_type()
1605 * includes any inter-chunk consistency check that libpng performs. Assume in current_type()
1609 if (file->chunk != NULL) in current_type()
1611 png_uint_32 type = file->chunk->chunk_type; in current_type()
1629 setpos(struct chunk *chunk) in setpos() argument
1631 * chunk. As a side effect the read_count in the file is reset to 8, just in setpos()
1635 chunk->file->read_count = 8; in setpos()
1636 file_setpos(chunk->file, &chunk->chunk_data_pos); in setpos()
1639 /* Specific chunk handling - called for each chunk header, all special chunk
1658 struct chunk *chunk = file->chunk; in process_zTXt_iCCP() local
1662 assert(chunk != NULL && file->idat == NULL); in process_zTXt_iCCP()
1663 length = chunk->chunk_length; in process_zTXt_iCCP()
1664 setpos(chunk); in process_zTXt_iCCP()
1679 chunk_message(chunk, "too short"); in process_zTXt_iCCP()
1687 struct chunk *chunk = file->chunk; in process_iTXt() local
1691 assert(chunk != NULL && file->idat == NULL); in process_iTXt()
1692 length = chunk->chunk_length; in process_iTXt()
1693 setpos(chunk); in process_iTXt()
1733 log_error(file, INVALID_ERROR_CODE, "iTXt chunk length"); in process_iTXt()
1753 png_uint_32 idat_length; /* Cache of current chunk length */
1770 assert(file->chunk != NULL); in IDAT_end()
1771 chunk_end(&file->chunk); in IDAT_end()
1782 /* When the chunk is png_IDAT instantiate an IDAT control structure in place in IDAT_init()
1783 * of a chunk control structure. The IDAT will instantiate a chunk control in IDAT_init()
1789 assert(file->chunk == NULL); in IDAT_init()
1803 /* Now the chunk. The allocator calls the initializer of the new chunk and in IDAT_init()
1804 * stores the result in file->chunk: in IDAT_init()
1806 file->alloc(file, 0/*chunk*/); in IDAT_init()
1807 assert(file->chunk != NULL); in IDAT_init()
1817 /* Return the length for the next IDAT chunk, taking into account in rechunk_length()
1823 if (len == 0) /* use original chunk lengths */ in rechunk_length()
1831 /* Otherwise rechunk_length is called at the end of a chunk for the length in rechunk_length()
1840 /* Return length of the *next* chunk */ in rechunk_length()
1853 /* The chunk size is the lesser of file->idat_max and the number in rechunk_length()
1903 * Initially the function returns false, indicating that the chunk should not in process_IDAT()
1904 * be written. It does this until the last IDAT chunk is passed in, then it in process_IDAT()
1916 assert(file->idat != NULL && file->chunk != NULL); in process_IDAT()
1923 * At the end of the list of chunks, where the type of the next chunk is not in process_IDAT()
1942 list->lengths[(list->count)++] = file->chunk->chunk_length; in process_IDAT()
1944 /* The type of the next chunk was recorded in the file control structure by in process_IDAT()
1950 /* This is the final IDAT chunk, so run the tests to check for the too far in process_IDAT()
1952 * to the start of the first chunk data, which is stored in the original in process_IDAT()
1953 * chunk allocation. in process_IDAT()
1955 setpos(file->chunk); in process_IDAT()
1966 file->chunk->uncompressed_bytes, file->chunk->uncompressed_digits); in process_IDAT()
1974 /* Return the stream to the start of the first IDAT chunk; the length in process_IDAT()
1975 * is set in the write case below but the input chunk variables must be in process_IDAT()
1978 setpos(file->chunk); in process_IDAT()
1984 idat->idat_index = 0; /* Index into chunk data */ in process_IDAT()
1986 /* Update the chunk length to the correct value for the IDAT chunk: */ in process_IDAT()
1987 file->chunk->chunk_length = rechunk_length(idat, 1/*start*/); in process_IDAT()
2004 struct chunk * chunk; member
2076 type_name(zlib->chunk->chunk_type, stderr); in zlib_message()
2110 type_name(zlib->chunk->chunk_type, stdout); in zlib_end()
2124 /* This is a zlib read error; the chunk will be skipped. For an IDAT in zlib_end()
2135 type_name(zlib->chunk->chunk_type, stdout); in zlib_end()
2185 zlib_init(struct zlib *zlib, struct IDAT *idat, struct chunk *chunk, in zlib_init() argument
2192 zlib->chunk = chunk; in zlib_init()
2193 zlib->file = chunk->file; in zlib_init()
2194 zlib->global = chunk->global; in zlib_init()
2441 /* At the end of the stream update the chunk with the accumulated in zlib_advance()
2446 struct chunk *chunk = zlib->chunk; in zlib_advance() local
2448 chunk->uncompressed_digits = uarb_copy(chunk->uncompressed_bytes, in zlib_advance()
2450 chunk->compressed_digits = uarb_copy(chunk->compressed_bytes, in zlib_advance()
2452 chunk->rewrite_buffer[0] = zlib->header[0]; in zlib_advance()
2453 chunk->rewrite_buffer[1] = zlib->header[1]; in zlib_advance()
2458 chunk->rewrite_offset = zlib->rewrite_offset; in zlib_advance()
2459 chunk->rewrite_length = 2; in zlib_advance()
2464 chunk->rewrite_offset = 0; in zlib_advance()
2465 chunk->rewrite_length = 0; in zlib_advance()
2469 chunk_message(chunk, "extra compressed data"); in zlib_advance()
2483 * compressed data in the chunk it handles (if it sees Z_STREAM_END before in zlib_run()
2485 * the correct chunk length, so the problem should only ever be detected once in zlib_run()
2486 * for each chunk. zlib_advance outputs the error message, though see the in zlib_run()
2497 /* 'rewrite_offset' is the offset of the LZ data within the chunk, for in zlib_run()
2503 * positioned at the start of the first IDAT chunk data. in zlib_run()
2541 chunk_message(zlib->chunk, in zlib_run()
2579 struct chunk *chunk = zlib->chunk; in zlib_run() local
2582 assert(zlib->rewrite_offset < chunk->chunk_length); in zlib_run()
2584 rc = zlib_advance(zlib, chunk->chunk_length - zlib->rewrite_offset); in zlib_run()
2586 /* The extra bytes in the chunk are handled now by adjusting the chunk in zlib_run()
2588 * the PNG chunk (although clearly this is not necessary.) zlib_advance in zlib_run()
2591 chunk->chunk_length -= zlib->extra_bytes; in zlib_run()
2599 * not) chunk. In fact it is zlib_run that handles the difference in reading in zlib_check()
2600 * a single chunk and a list of IDAT chunks. in zlib_check()
2618 if (zlib_init(&zlib, file->idat, file->chunk, 0/*window bits*/, offset)) in zlib_check()
2657 chunk_message(zlib.chunk, "zlib checksum"); in zlib_check()
2668 /* Unrecoverable error; skip the chunk; a zlib_message has already in zlib_check()
2737 else /* zlib initialization failed - skip the chunk */ in zlib_check()
2757 * the per-file routine contains the chunk and IDAT control structures.
2776 /* Called when the chunk data has been read, next_length and next_type in process_chunk()
2777 * will be set for the next chunk (or 0 if this is IEND). in process_chunk()
2780 * next chunk to write because if a chunk is skipped this return calls back in process_chunk()
2801 * than SKIP_BAD_CRC ignore the bad CRC and return the chunk, with a in process_chunk()
2803 * chunk, which will result in a fatal error if the chunk is critical. in process_chunk()
2813 stop(file, READ_ERROR_CODE, "bad CRC in critical chunk"); in process_chunk()
2826 * chunk.) in process_chunk()
2831 /* The chunk may still be skipped if problems are detected in the LZ data, in process_chunk()
2832 * however the LZ data check requires a chunk. Handle this by instantiating in process_chunk()
2833 * a chunk unless an IDAT is already instantiated (IDAT control structures in process_chunk()
2834 * instantiate their own chunk.) in process_chunk()
2837 file->alloc(file, 0/*chunk*/); in process_chunk()
2844 /* The chunk length must be updated for process_IDAT */ in process_chunk()
2845 assert(file->chunk != NULL); in process_chunk()
2846 assert(file->chunk->chunk_type == png_IDAT); in process_chunk()
2847 file->chunk->chunk_length = file->length; in process_chunk()
2851 * this chunk have been copied. Notice that the IDAT chunks only make a in process_chunk()
2852 * copy of the position of the first chunk, this is fine - process_IDAT does in process_chunk()
2853 * not need the position of this chunk. in process_chunk()
2860 * function the chunk will be skipped. The rewrite is cancelled here so that in process_chunk()
2861 * it can be set in the per-chunk processing. in process_chunk()
2863 file->chunk->rewrite_length = 0; in process_chunk()
2864 file->chunk->rewrite_offset = 0; in process_chunk()
2876 struct chunk *chunk = file->chunk; in process_chunk() local
2878 if (chunk->chunk_length != 13) in process_chunk()
2882 setpos(chunk); in process_chunk()
2902 chunk_end(&file->chunk); in process_chunk()
2909 chunk_end(&file->chunk); in process_chunk()
2921 /* Control reaches this point if the chunk must be skipped. For chunks other in process_chunk()
2923 * the chunk will not be passed to libpng. For IDAT it means that the end of in process_chunk()
2925 * (IDAT) chunk. If the LZ data in an IDAT stream cannot be read 'stop' must in process_chunk()
2931 /* This is the generic code to skip the current chunk; simply jump to the in process_chunk()
2955 /* The stream seems to be messed up, attempt to resync from the current chunk in sync_stream()
2970 /* Return to the start of the chunk data */ in sync_stream()
2976 /* Ignore the recorded chunk length, proceed through the data looking for in sync_stream()
2979 * length, chunk-type pair. in sync_stream()
2994 * else expect a following chunk header. in sync_stream()
3018 /* Examine the 8 bytes for a valid chunk header. */ in sync_stream()
3040 * while checking a chunk header. This code is slightly tricky - if in sync_stream()
3044 * after the IEND CRC and other chunk leave it after the *next* chunk in sync_stream()
3074 * of the chunk data *and* the input file must be at this position. This in read_chunk()
3075 * routine (via process_chunk) instantiates a chunk or IDAT control structure in read_chunk()
3077 * file::data_pos for the chunk after this one. For an IDAT chunk the whole in read_chunk()
3079 * encountered, and the file fields will be set for the chunk after the end in read_chunk()
3083 * of the IEND chunk will have been read. in read_chunk()
3102 /* Start the read_crc calculation with the chunk type, then read to the end in read_chunk()
3103 * of the chunk data (without processing it in any way) to check that it is in read_chunk()
3128 * chunk. in read_chunk()
3147 * chunk's data, its CRC and the length and type of the next chunk) or the in read_chunk()
3148 * next chunk length/type are invalid. Notice that the cases that end up in read_chunk()
3181 png_uint_32 type, length; /* For the chunk be *WRITTEN* */ in read_callback()
3182 struct chunk *chunk; in read_callback() local
3188 /* The callback always reads ahead by 8 bytes - the signature or chunk header in read_callback()
3190 * executed once for the signature and once for the first chunk right at the in read_callback()
3224 /* The first chunk must be a well formed IHDR (this could be relaxed to in read_callback()
3238 chunk = file->chunk; in read_callback()
3240 if (chunk != NULL) in read_callback()
3242 length = chunk->chunk_length; in read_callback()
3243 type = chunk->chunk_type; in read_callback()
3259 /* Complete the read of a chunk; as a side effect this also instantiates in read_callback()
3260 * a chunk control structure and sets the file length/type/data_pos fields in read_callback()
3261 * for the *NEXT* chunk header. in read_callback()
3264 * next_ fields will refer to the chunk after the last IDAT. in read_callback()
3266 * NOTE: read_chunk only returns when it has read a chunk that must now be in read_callback()
3269 if (file->state != STATE_SIGNATURE && chunk == NULL) in read_callback()
3274 chunk = file->chunk; in read_callback()
3275 assert(chunk != NULL); in read_callback()
3278 length = chunk->chunk_length; in read_callback()
3279 type = chunk->chunk_type; in read_callback()
3281 /* And start writing the new chunk. */ in read_callback()
3285 /* The chunk_ fields describe a chunk that must be written, or hold the in read_callback()
3303 * that's all that is required and we can go to normal chunk in read_callback()
3321 assert(chunk != NULL); in read_callback()
3329 chunk->write_crc = crc_init_4(type); in read_callback()
3331 setpos(chunk); in read_callback()
3336 assert(chunk != NULL); in read_callback()
3339 * png_uint_32 value until the whole chunk data has been written. in read_callback()
3343 /* Write the chunk data, normally this just comes from in read_callback()
3345 * chunk which is zlib data and which must be rewritten, in read_callback()
3358 * held in the struct IDAT members. The chunk members, in in read_callback()
3360 * refer to the output chunk. in read_callback()
3364 /* Advance one chunk */ in read_callback()
3395 /* And skip 12 bytes to the next chunk data */ in read_callback()
3400 * the information is always the current IDAT chunk and the in read_callback()
3410 if (chunk->rewrite_length > 0) in read_callback()
3412 if (chunk->rewrite_offset > 0) in read_callback()
3413 --(chunk->rewrite_offset); in read_callback()
3417 b = chunk->rewrite_buffer[0]; in read_callback()
3418 memmove(chunk->rewrite_buffer, chunk->rewrite_buffer+1, in read_callback()
3419 (sizeof chunk->rewrite_buffer)- in read_callback()
3420 (sizeof chunk->rewrite_buffer[0])); in read_callback()
3422 --(chunk->rewrite_length); in read_callback()
3426 chunk->write_crc = crc_one_byte(chunk->write_crc, b); in read_callback()
3435 case 8: b = chunk->write_crc >> 24; goto write_crc; in read_callback()
3436 case 9: b = chunk->write_crc >> 16; goto write_crc; in read_callback()
3437 case 10: b = chunk->write_crc >> 8; goto write_crc; in read_callback()
3440 b = chunk->write_crc; in read_callback()
3447 chunk->write_crc ^ 0xffffffff); in read_callback()
3453 * the end of an *output* chunk - the length calculated by in read_callback()
3462 /* Write another IDAT chunk. Call rechunk_length to in read_callback()
3465 length = chunk->chunk_length = in read_callback()
3468 file->write_count = 0; /* for the new chunk */ in read_callback()
3474 /* Entered at the end of a non-IDAT chunk and at the end of in read_callback()
3477 if (chunk->rewrite_length > 0 || chunk->rewrite_offset > 0) in read_callback()
3481 * chunk and move the input file to the position after the in read_callback()
3482 * *next* chunk header if required. in read_callback()
3488 chunk_end(&file->chunk); in read_callback()
3510 /* Bundle the file and an uninitialized chunk and IDAT control structure
3511 * together to allow implementation of the chunk/IDAT allocate routine.
3516 struct chunk chunk; member
3529 /* This just returns the (file*). The chunk and idat control structures in get_control()
3548 else /* chunk */ in allocate()
3550 assert(file->chunk == NULL); in allocate()
3551 chunk_init(&control->chunk, file); in allocate()
3676 " of zlib issues founds for each compressed chunk and the IDAT stream in", in usage()
3705 " is omitted the original chunk sizes will not be changed. When the", in usage()
3745 " 0x01: The zlib too-far-back error existed in at least one chunk.", in usage()
3746 " 0x02: At least one chunk had a CRC error.", in usage()
3747 " 0x04: A chunk length was incorrect.", in usage()
3773 " compressed chunk in which it is encountered. An integrity problem of the", in usage()
3774 " PNG stream caused by a bug in libpng which wrote an incorrect chunk length", in usage()
3775 " is also fixed. Chunk CRC errors are automatically fixed up.", in usage()
3789 " stream of a chunk. They have the following format, which is SUBJECT TO", in usage()
3792 " chunk reason comp-level p1 p2 p3 p4 file", in usage()
3797 " chunk ERR status code read-errno write-errno message file", in usage()
3798 " chunk SKP comp-level file-bits zlib-rc compressed message file", in usage()
3799 " chunk ??? comp-level file-bits ok-bits compressed uncompress file", in usage()
3803 "$1 chunk: The chunk type of a chunk in the file or 'HEAD' if a problem", in usage()
3811 " SKP: The chunk was skipped because of a zlib issue (zlib-rc) with", in usage()