Skip to content

Commit

Permalink
Merge pull request #449 from maage/fixes2
Browse files Browse the repository at this point in the history
Some small fixes to enhance robustness
  • Loading branch information
jonsneyers authored Sep 20, 2017
2 parents 53ea740 + f2e65d0 commit 52a1b2d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ uninstall:
rm -f /usr/lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-flif$(LIBEXT)

clean:
rm -f flif dflif lib*flif*$(LIBEXT)* viewflif flif.asan flif.dbg flif.prof flif.stats test-interface $(FILES_O) library/flif-interface.o
rm -f flif dflif lib*flif*$(LIBEXT)* viewflif flif.asan flif.dbg flif.prof flif.stats test-interface $(FILES_O) flif.o library/flif-interface.o


# The targets below are only meant for developers
Expand Down
6 changes: 5 additions & 1 deletion src/flif-dec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ void flif_decode_FLIF2_inner_interpol(Images &images, const ColorRanges *ranges,
uint32_t cols = image.cols(z);
for (uint32_t r = 0; r < rows; r++) {
for (uint32_t c = 1; c < cols; c += 2) {
plane.set(z,r,c, predict_plane_vertical(plane,z,p,r,c,rows,0));
plane.set(z,r,c, predict_plane_vertical(plane,z,p,r,c,cols,0));
}
}
}
Expand Down Expand Up @@ -1036,6 +1036,10 @@ bool flif_decode(IO& io, Images &images, callback_t callback, void *user_data, i
if (width < 1 || height < 1) {e_printf("Invalid FLIF header\n"); return false;}

if (numFrames > 1) numFrames = read_big_endian_varint(io)+2;
if (numFrames < 0) {
e_printf("Unsensical number of frames < 0.\n");
return false;
}
#ifndef SUPPORT_ANIMATION
if (numFrames > 1) {
e_printf("This FLIF cannot decode animations. Please compile with SUPPORT_ANIMATION.\n");
Expand Down
4 changes: 4 additions & 0 deletions src/flif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,10 @@ int main(int argc, char **argv)
e_printf("Too many arguments.\n");
return 1;
}
if (mode == 2 && options.keep_palette) {
e_printf("Transcode (-t) does not work with -k as it requires either to be PNG.\n");
return 1;
}

#ifdef HAS_ENCODER
if (options.chroma_subsampling)
Expand Down
13 changes: 9 additions & 4 deletions src/image/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ struct PlaneVisitor {
virtual ~PlaneVisitor() {}
};

#define SCALED(x) (((x-1)>>scale)+1)
#define SCALED(x) ((x)==0?0:((((x)-1)>>scale)+1))
#ifdef USE_SIMD
// pad to a multiple of 8, leaving room for alignment
#define PAD(x) ((x) + 16)
Expand Down Expand Up @@ -560,7 +560,7 @@ class Image {
depth = other.depth;
other.depth = 0;
#endif
metadata = other.metadata;
metadata = std::move(other.metadata);

other.width = other.height = 0;
other.minval = other.maxval = 0;
Expand Down Expand Up @@ -599,8 +599,11 @@ class Image {
palette_image = other.palette_image;
alpha_zero_special = other.alpha_zero_special;
frame_delay = other.frame_delay;
// col_begin = other.col_begin; // not needed and meaningless after downsampling
// col_end = other.col_end;
// assume downsample is always able to allocate enough space
col_begin.clear();
col_begin.resize(height,0);
col_end.clear();
col_end.resize(height,width);
seen_before = other.seen_before;
fully_decoded = other.fully_decoded;
clear();
Expand Down Expand Up @@ -924,9 +927,11 @@ class Image {
}

size_t rows(int zoomlevel) const {
if (rows() <= 0) return 0;
return 1+(rows()-1)/zoom_rowpixelsize(zoomlevel);
}
size_t cols(int zoomlevel) const {
if (cols() <= 0) return 0;
return 1+(cols()-1)/zoom_colpixelsize(zoomlevel);
}
int zooms() const {
Expand Down
6 changes: 5 additions & 1 deletion src/transform/palette_A.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ class TransformPaletteA : public Transform<IO> {
}
}
uint64_t max_nb_colors = 1;
for (int p=0; p<4; p++) max_nb_colors *= 1+srcRanges->max(p)-srcRanges->min(p);
for (int p=0; p<4; p++) {
max_nb_colors *= 1+srcRanges->max(p)-srcRanges->min(p);
// Need to guard integer overflow: 65536^3
if (Palette_vector.size() < max_nb_colors) return true;
}
if (Palette_vector.size() == max_nb_colors) return false; // don't make a trivial palette
// printf("Palette size: %lu\n",Palette.size());
return true;
Expand Down

0 comments on commit 52a1b2d

Please sign in to comment.