Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/lvandeve/lodepng.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLode <lvandeve@gmail.com>2020-10-17 15:29:32 +0300
committerLode <lvandeve@gmail.com>2020-10-17 15:36:06 +0300
commit7fdcc96a5e5864eee72911c3ca79b1d9f0d12292 (patch)
tree1536dc1884b4683090f3197c227c6930908c010a /lodepng.h
parent34628e89e80cd007179b25b0b2695e6af0f57fac (diff)
prevent too huge text chunks or icc profiles
Diffstat (limited to 'lodepng.h')
-rw-r--r--lodepng.h50
1 files changed, 41 insertions, 9 deletions
diff --git a/lodepng.h b/lodepng.h
index a386459..6801cb7 100644
--- a/lodepng.h
+++ b/lodepng.h
@@ -1,5 +1,5 @@
/*
-LodePNG version 20200306
+LodePNG version 20201017
Copyright (c) 2005-2020 Lode Vandevenne
@@ -270,12 +270,21 @@ struct LodePNGDecompressSettings {
unsigned ignore_adler32; /*if 1, continue and don't give an error message if the Adler32 checksum is corrupted*/
unsigned ignore_nlen; /*ignore complement of len checksum in uncompressed blocks*/
- /*use custom zlib decoder instead of built in one (default: null)*/
+ /*Maximum decompressed size, beyond this the decoder may (and is encouraged to) stop decoding,
+ return an error, output a data size > max_output_size and all the data up to that point. This is
+ not hard limit nor a guarantee, but can prevent excessive memory usage. This setting is
+ ignored by the PNG decoder, but is used by the deflate/zlib decoder and can be used by custom ones.
+ Set to 0 to impose no limit (the default).*/
+ size_t max_output_size;
+
+ /*use custom zlib decoder instead of built in one (default: null).
+ Should return 0 if success, any non-0 if error (numeric value not exposed).*/
unsigned (*custom_zlib)(unsigned char**, size_t*,
const unsigned char*, size_t,
const LodePNGDecompressSettings*);
/*use custom deflate decoder instead of built in one (default: null)
- if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate)*/
+ if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate).
+ Should return 0 if success, any non-0 if error (numeric value not exposed).*/
unsigned (*custom_inflate)(unsigned char**, size_t*,
const unsigned char*, size_t,
const LodePNGDecompressSettings*);
@@ -454,30 +463,36 @@ typedef struct LodePNGInfo {
unsigned background_b; /*blue component of suggested background color*/
/*
- non-international text chunks (tEXt and zTXt)
+ Non-international text chunks (tEXt and zTXt)
The char** arrays each contain num strings. The actual messages are in
text_strings, while text_keys are keywords that give a short description what
the actual text represents, e.g. Title, Author, Description, or anything else.
- All the string fields below including keys, names and language tags are null terminated.
+ All the string fields below including strings, keys, names and language tags are null terminated.
The PNG specification uses null characters for the keys, names and tags, and forbids null
characters to appear in the main text which is why we can use null termination everywhere here.
- A keyword is minimum 1 character and maximum 79 characters long. It's
- discouraged to use a single line length longer than 79 characters for texts.
+ A keyword is minimum 1 character and maximum 79 characters long (plus the
+ additional null terminator). It's discouraged to use a single line length
+ longer than 79 characters for texts.
Don't allocate these text buffers yourself. Use the init/cleanup functions
correctly and use lodepng_add_text and lodepng_clear_text.
+
+ Standard text chunk keywords and strings are encoded using Latin-1.
*/
size_t text_num; /*the amount of texts in these char** buffers (there may be more texts in itext)*/
char** text_keys; /*the keyword of a text chunk (e.g. "Comment")*/
char** text_strings; /*the actual text*/
/*
- international text chunks (iTXt)
+ International text chunks (iTXt)
Similar to the non-international text chunks, but with additional strings
- "langtags" and "transkeys".
+ "langtags" and "transkeys", and the following text encodings are used:
+ keys: Latin-1, langtags: ASCII, transkeys and strings: UTF-8.
+ keys must be 1-79 characters (plus the additional null terminator), the other
+ strings are any length.
*/
size_t itext_num; /*the amount of international texts in this PNG*/
char** itext_keys; /*the English keyword of the text chunk (e.g. "Comment")*/
@@ -639,8 +654,19 @@ typedef struct LodePNGDecoderSettings {
#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS
unsigned read_text_chunks; /*if false but remember_unknown_chunks is true, they're stored in the unknown chunks*/
+
/*store all bytes from unknown chunks in the LodePNGInfo (off by default, useful for a png editor)*/
unsigned remember_unknown_chunks;
+
+ /* maximum size for decompressed text chunks. If a text chunk's text is larger than this, an error is returned,
+ unless reading text chunks is disabled or this limit is set higher or disabled. Set to 0 to allow any size.
+ By default it is a value that prevents unreasonably large strings from hogging memory. */
+ size_t max_text_size;
+
+ /* maximum size for compressed ICC chunks. If the ICC profile is larger than this, an error will be returned. Set to
+ 0 to allow any size. By default this is a value that prevents ICC profiles that would be much larger than any
+ legitimate profile could be to hog memory. */
+ size_t max_icc_size;
#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/
} LodePNGDecoderSettings;
@@ -1505,6 +1531,11 @@ of the error in English as a string.
Check the implementation of lodepng_error_text to see the meaning of each code.
+It is not recommended to use the numerical values to programmatically make
+different decisions based on error types as the numbers are not guaranteed to
+stay backwards compatible. They are for human consumption only. Programmatically
+only 0 or non-0 matter.
+
8. chunks and PNG editing
-------------------------
@@ -1775,6 +1806,7 @@ symbol.
Not all changes are listed here, the commit history in github lists more:
https://github.com/lvandeve/lodepng
+*) 17 okt 2020: prevent decoding too large text/icc chunks by default.
*) 06 mar 2020: simplified some of the dynamic memory allocations.
*) 12 jan 2020: (!) added 'end' argument to lodepng_chunk_next to allow correct
overflow checks.