diff --git a/CHANGELOG.md b/CHANGELOG.md index b9af60c1..4d65bd51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ### 1.1.9 - proguard configuration is now bundled with the library - [#193](https://github.com/koral--/android-gif-drawable/pull/193) +- Android gradle plugin updated to 1.3.0 +- fixed segfault when frame is not confined to canvas - [#196](https://github.com/koral--/android-gif-drawable/issues/196), [#194](https://github.com/koral--/android-gif-drawable/issues/194) ### 1.1.8 - toolchain changed to clang diff --git a/build.gradle b/build.gradle index f16dc8ac..bacf18b0 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:1.2.3' + classpath 'com.android.tools.build:gradle:1.3.0' } } diff --git a/src/main/jni/decoding.c b/src/main/jni/decoding.c index 99f0b3d9..7f9f79a5 100644 --- a/src/main/jni/decoding.c +++ b/src/main/jni/decoding.c @@ -14,12 +14,23 @@ void DDGifSlurp(GifInfo *info, bool shouldDecode) { if (DGifGetImageDesc(info->gifFilePtr, !shouldDecode) == GIF_ERROR) return; - if (info->gifFilePtr->Image.Left + info->gifFilePtr->Image.Width > info->gifFilePtr->SWidth) { - info->gifFilePtr->Image.Width = info->gifFilePtr->SWidth - info->gifFilePtr->Image.Left; - } + const uint_fast16_t requiredScreenWidth = info->gifFilePtr->Image.Left + info->gifFilePtr->Image.Width; + const uint_fast16_t requiredScreenHeight = info->gifFilePtr->Image.Top + info->gifFilePtr->Image.Height; - if (info->gifFilePtr->Image.Top + info->gifFilePtr->Image.Height > info->gifFilePtr->SHeight) { - info->gifFilePtr->Image.Height = info->gifFilePtr->SHeight - info->gifFilePtr->Image.Top; + if (requiredScreenWidth > info->gifFilePtr->SWidth || requiredScreenHeight > info->gifFilePtr->SHeight) { + if (shouldDecode) { + void *tmpRasterBits = realloc(info->rasterBits, + requiredScreenWidth * requiredScreenHeight * sizeof(GifPixelType)); + if (tmpRasterBits == NULL) { + info->gifFilePtr->Error = D_GIF_ERR_NOT_ENOUGH_MEM; + return; + } + info->rasterBits = tmpRasterBits; + } + else { + info->gifFilePtr->SWidth = requiredScreenWidth; + info->gifFilePtr->SHeight = requiredScreenHeight; + } } if (shouldDecode) { @@ -41,7 +52,8 @@ void DDGifSlurp(GifInfo *info, bool shouldDecode) { } else { if (DGifGetLine( - info->gifFilePtr, info->rasterBits, info->gifFilePtr->Image.Width * info->gifFilePtr->Image.Height) == GIF_ERROR) + info->gifFilePtr, info->rasterBits, + info->gifFilePtr->Image.Width * info->gifFilePtr->Image.Height) == GIF_ERROR) return; } return; @@ -61,7 +73,8 @@ void DDGifSlurp(GifInfo *info, bool shouldDecode) { return; if (!shouldDecode) { GraphicsControlBlock *tmpInfos = realloc(info->controlBlock, - (info->gifFilePtr->ImageCount + 1) * sizeof(GraphicsControlBlock)); + (info->gifFilePtr->ImageCount + 1) * + sizeof(GraphicsControlBlock)); if (tmpInfos == NULL) { info->gifFilePtr->Error = D_GIF_ERR_NOT_ENOUGH_MEM; return; diff --git a/src/main/jni/gif.c b/src/main/jni/gif.c index aaa5de6e..a58bfa12 100644 --- a/src/main/jni/gif.c +++ b/src/main/jni/gif.c @@ -9,7 +9,7 @@ static JavaVM *g_jvm; static struct JavaVMAttachArgs attachArgs = {.version=JNI_VERSION_1_6, .group=NULL, .name="GifIOThread"}; -inline JNIEnv *getEnv() { +static inline JNIEnv *getEnv() { JNIEnv *env; if ((*g_jvm)->AttachCurrentThread(g_jvm, &env, &attachArgs) == JNI_OK) diff --git a/src/main/jni/gif.h b/src/main/jni/gif.h index e2c4d906..0475ec98 100644 --- a/src/main/jni/gif.h +++ b/src/main/jni/gif.h @@ -159,8 +159,6 @@ bool isSourceNull(void *ptr, JNIEnv *env); static uint_fast8_t fileRead(GifFileType *gif, GifByteType *bytes, uint_fast8_t size); -inline JNIEnv *getEnv(); - static uint_fast8_t directByteBufferReadFun(GifFileType *gif, GifByteType *bytes, uint_fast8_t size); static uint_fast8_t byteArrayReadFun(GifFileType *gif, GifByteType *bytes, uint_fast8_t size);