Skip to content

Commit e4237f4

Browse files
committed
LIB: update lodepng
1 parent 453e70b commit e4237f4

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

src/lib/lodepng.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
LodePNG version 20170917
2+
LodePNG version 20180114
33
4-
Copyright (c) 2005-2017 Lode Vandevenne
4+
Copyright (c) 2005-2018 Lode Vandevenne
55
66
This software is provided 'as-is', without any express or implied
77
warranty. In no event will the authors be held liable for any damages
@@ -39,7 +39,7 @@ Rename this file to lodepng.cpp to use it for C++, or to lodepng.c to use it for
3939
#pragma warning( disable : 4996 ) /*VS does not like fopen, but fopen_s is not standard C so unusable here*/
4040
#endif /*_MSC_VER */
4141

42-
const char* LODEPNG_VERSION_STRING = "20170917";
42+
const char* LODEPNG_VERSION_STRING = "20180114";
4343

4444
/*
4545
This source file is built up in the following large parts. The code sections
@@ -4565,12 +4565,20 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
45654565
const unsigned char* data; /*the data in the chunk*/
45664566

45674567
/*error: size of the in buffer too small to contain next chunk*/
4568-
if((size_t)((chunk - in) + 12) > insize || chunk < in) CERROR_BREAK(state->error, 30);
4568+
if((size_t)((chunk - in) + 12) > insize || chunk < in)
4569+
{
4570+
if(state->decoder.ignore_end) break; /*other errors may still happen though*/
4571+
CERROR_BREAK(state->error, 30);
4572+
}
45694573

45704574
/*length of the data of the chunk, excluding the length bytes, chunk type and CRC bytes*/
45714575
chunkLength = lodepng_chunk_length(chunk);
45724576
/*error: chunk length larger than the max PNG chunk size*/
4573-
if(chunkLength > 2147483647) CERROR_BREAK(state->error, 63);
4577+
if(chunkLength > 2147483647)
4578+
{
4579+
if(state->decoder.ignore_end) break; /*other errors may still happen though*/
4580+
CERROR_BREAK(state->error, 63);
4581+
}
45744582

45754583
if((size_t)((chunk - in) + chunkLength + 12) > insize || (chunk + chunkLength + 12) < in)
45764584
{
@@ -4657,7 +4665,10 @@ static void decodeGeneric(unsigned char** out, unsigned* w, unsigned* h,
46574665
else /*it's not an implemented chunk type, so ignore it: skip over the data*/
46584666
{
46594667
/*error: unknown critical chunk (5th bit of first byte of chunk type is 0)*/
4660-
if(!lodepng_chunk_ancillary(chunk)) CERROR_BREAK(state->error, 69);
4668+
if(!state->decoder.ignore_critical && !lodepng_chunk_ancillary(chunk))
4669+
{
4670+
CERROR_BREAK(state->error, 69);
4671+
}
46614672

46624673
unknown = 1;
46634674
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
@@ -4822,6 +4833,8 @@ void lodepng_decoder_settings_init(LodePNGDecoderSettings* settings)
48224833
settings->remember_unknown_chunks = 0;
48234834
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
48244835
settings->ignore_crc = 0;
4836+
settings->ignore_critical = 0;
4837+
settings->ignore_end = 0;
48254838
lodepng_decompress_settings_init(&settings->zlibsettings);
48264839
}
48274840

src/lib/lodepng.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
LodePNG version 20170917
2+
LodePNG version 20180114
33
4-
Copyright (c) 2005-2017 Lode Vandevenne
4+
Copyright (c) 2005-2018 Lode Vandevenne
55
66
This software is provided 'as-is', without any express or implied
77
warranty. In no event will the authors be held liable for any damages
@@ -255,6 +255,7 @@ const char* lodepng_error_text(unsigned code);
255255
typedef struct LodePNGDecompressSettings LodePNGDecompressSettings;
256256
struct LodePNGDecompressSettings
257257
{
258+
/* Check LodePNGDecoderSettings for more ignorable errors */
258259
unsigned ignore_adler32; /*if 1, continue and don't give an error message if the Adler32 checksum is corrupted*/
259260

260261
/*use custom zlib decoder instead of built in one (default: null)*/
@@ -520,7 +521,10 @@ typedef struct LodePNGDecoderSettings
520521
{
521522
LodePNGDecompressSettings zlibsettings; /*in here is the setting to ignore Adler32 checksums*/
522523

524+
/* Check LodePNGDecompressSettings for more ignorable errors */
523525
unsigned ignore_crc; /*ignore CRC checksums*/
526+
unsigned ignore_critical; /*ignore unknown critical chunks*/
527+
unsigned ignore_end; /*ignore issues at end of file if possible (missing IEND chunk, too large chunk, ...)*/
524528

525529
unsigned color_convert; /*whether to convert the PNG to the color type you want. Default: yes*/
526530

@@ -1567,6 +1571,8 @@ For decoding:
15671571
state.decoder.zlibsettings.ignore_adler32: ignore ADLER32 checksums
15681572
state.decoder.zlibsettings.custom_...: use custom inflate function
15691573
state.decoder.ignore_crc: ignore CRC checksums
1574+
state.decoder.ignore_critical: ignore unknown critical chunks
1575+
state.decoder.ignore_end: ignore missing IEND chunk. May fail if this corruption causes other errors
15701576
state.decoder.color_convert: convert internal PNG color to chosen one
15711577
state.decoder.read_text_chunks: whether to read in text metadata chunks
15721578
state.decoder.remember_unknown_chunks: whether to read in unknown chunks
@@ -1608,6 +1614,7 @@ yyyymmdd.
16081614
Some changes aren't backwards compatible. Those are indicated with a (!)
16091615
symbol.
16101616
1617+
*) 14 jan 2018: allow optionally ignoring a few more recoverable errors
16111618
*) 17 sep 2017: fix memory leak for some encoder input error cases
16121619
*) 27 nov 2016: grey+alpha auto color model detection bugfix
16131620
*) 18 apr 2016: Changed qsort to custom stable sort (for platforms w/o qsort).

0 commit comments

Comments
 (0)