[Android] thumbnailer: fix rounding error

Ludovic Fauvet git at videolan.org
Wed Sep 19 21:06:07 CEST 2012


vlc-ports/android | branch: master | Ludovic Fauvet <etix at videolan.org> | Wed Sep 19 20:58:14 2012 +0200| [b6d252bdb353d88b9dd7c343466d56d5f439b4d3] | committer: Ludovic Fauvet

thumbnailer: fix rounding error

The allocated memory used to store the thumbnail was insufficient and
caused a memory corruption on the Nexus7 tablet.

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=b6d252bdb353d88b9dd7c343466d56d5f439b4d3
---

 vlc-android/jni/thumbnailer.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/vlc-android/jni/thumbnailer.c b/vlc-android/jni/thumbnailer.c
index 0e49fd2..1eb7744 100644
--- a/vlc-android/jni/thumbnailer.c
+++ b/vlc-android/jni/thumbnailer.c
@@ -180,12 +180,12 @@ jbyteArray Java_org_videolan_vlc_LibVLC_getThumbnail(JNIEnv *env, jobject thiz,
     float screenAR = (float)width / height;
     if (screenAR < videoAR)
     {
-        picHeight = (float)width / videoAR;
+        picHeight = (float)width / videoAR + 1;
         sys->thumbnailOffset = (height - picHeight) / 2 * width * PIXEL_SIZE;
     }
     else
     {
-        picWidth = (float)height * videoAR;
+        picWidth = (float)height * videoAR + 1;
         sys->thumbnailOffset = (width - picWidth) / 2 * PIXEL_SIZE;
     }
 
@@ -194,7 +194,7 @@ jbyteArray Java_org_videolan_vlc_LibVLC_getThumbnail(JNIEnv *env, jobject thiz,
     sys->nbLines = picHeight;
 
     /* Allocate the memory to store the frames. */
-    unsigned picSize = sys->picPitch * picHeight;
+    size_t picSize = sys->picPitch * sys->nbLines;
     sys->frameData = malloc(picSize);
     if (sys->frameData == NULL)
     {



More information about the Android mailing list