Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix breakage with -DLODEPNG_NO_COMPILE_CRC #161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lodepng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2490,17 +2490,24 @@ const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk) {
}

unsigned lodepng_chunk_check_crc(const unsigned char* chunk) {
#ifndef LODEPNG_NO_COMPILE_CRC
unsigned length = lodepng_chunk_length(chunk);
unsigned CRC = lodepng_read32bitInt(&chunk[length + 8]);
/*the CRC is taken of the data and the 4 chunk type letters, not the length*/
unsigned checksum = lodepng_crc32(&chunk[4], length + 4);
if(CRC != checksum) return 1;
else return 0;
else
#endif
return 0;
}

void lodepng_chunk_generate_crc(unsigned char* chunk) {
unsigned length = lodepng_chunk_length(chunk);
#ifndef LODEPNG_NO_COMPILE_CRC
unsigned CRC = lodepng_crc32(&chunk[4], length + 4);
#else
unsigned CRC = 0;
#endif
lodepng_set32bitInt(chunk + 8 + length, CRC);
}

Expand Down Expand Up @@ -4078,13 +4085,15 @@ unsigned lodepng_inspect(unsigned* w, unsigned* h, LodePNGState* state,
/*error: only interlace methods 0 and 1 exist in the specification*/
if(info->interlace_method > 1) CERROR_RETURN_ERROR(state->error, 34);

#ifndef LODEPNG_NO_COMPILE_CRC
if(!state->decoder.ignore_crc) {
unsigned CRC = lodepng_read32bitInt(&in[29]);
unsigned checksum = lodepng_crc32(&in[12], 17);
if(CRC != checksum) {
CERROR_RETURN_ERROR(state->error, 57); /*invalid CRC*/
}
}
#endif

return state->error;
}
Expand Down