summaryrefslogtreecommitdiff
path: root/example_png_info.cpp
diff options
context:
space:
mode:
authorSlowRiot <rain.backnet@gmail.com>2014-11-27 04:13:51 +0000
committerSlowRiot <rain.backnet@gmail.com>2014-11-27 04:13:51 +0000
commite205cb35be0d53730ee8c8c8082255d3f50c5d12 (patch)
tree1d924292d24581ebad4bff1c7afd5437fd2f60b0 /example_png_info.cpp
parente14137419c1d444ed61a6789bd3dd6942cdc7405 (diff)
parent71b8c3ad7338b41b43676ad4212f6d820d4ce193 (diff)
Merge branch 'master' of https://github.com/lvandeve/lodepng
# By Lode (10) and others # Via Lode * 'master' of https://github.com/lvandeve/lodepng: fix for C fix examples better bitpointer checks small tweaks Update lodepng.h Update lodepng.cpp avoid too big pixel sizes predict idat size correctly for interlaced images unit test was a bit slow like that fix bug with encoding transparent single-pixel image protect against invalid chunk lengths in some tools fix pngdetail.cpp collapsing duplicate branch do not check unsigned windowsize for < 0 Conflicts: lodepng.cpp
Diffstat (limited to 'example_png_info.cpp')
-rw-r--r--example_png_info.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/example_png_info.cpp b/example_png_info.cpp
index 86f664a..afd845c 100644
--- a/example_png_info.cpp
+++ b/example_png_info.cpp
@@ -232,6 +232,10 @@ void displayFilterTypes(const std::vector<unsigned char>& buffer)
{
const unsigned char* cdata = lodepng_chunk_data_const(chunk);
unsigned clength = lodepng_chunk_length(chunk);
+ if(chunk + clength + 12 > end) {
+ std::cout << "invalid chunk length" << std::endl;
+ return;
+ }
for(unsigned i = 0; i < clength; i++)
{
@@ -276,12 +280,18 @@ Main
*/
int main(int argc, char *argv[]) /*list the chunks*/
{
- if(argc < 2)
+ bool ignore_checksums = false;
+ std::string filename = "";
+ for (int i = 1; i < argc; i++)
+ {
+ if(std::string(argv[i]) == "--ignore_checksums") ignore_checksums = true;
+ else filename = argv[i];
+ }
+ if(filename == "")
{
std::cout << "Please provide a filename to preview" << std::endl;
return 0;
}
- const char* filename = argv[1];
std::vector<unsigned char> buffer;
std::vector<unsigned char> image;
@@ -290,6 +300,12 @@ int main(int argc, char *argv[]) /*list the chunks*/
lodepng::load_file(buffer, filename); //load the image file with given filename
lodepng::State state;
+ if(ignore_checksums)
+ {
+ state.decoder.ignore_crc = 1;
+ state.decoder.zlibsettings.ignore_adler32 = 1;
+ }
+
unsigned error = lodepng::decode(image, w, h, state, buffer);
if(error)