m4v_h263: update width/height only when they are valid. Test: the file in the bug doesn't crash Bug: 37079296 Change-Id: Ie092971dda568119ca38ec67d65ccfc00df93185 (cherry picked from commit 0b5726782d5f9764325057870cef2750853f286a)
diff --git a/media/libstagefright/codecs/m4v_h263/dec/src/vop.cpp b/media/libstagefright/codecs/m4v_h263/dec/src/vop.cpp index 60c79a6..f18f789 100644 --- a/media/libstagefright/codecs/m4v_h263/dec/src/vop.cpp +++ b/media/libstagefright/codecs/m4v_h263/dec/src/vop.cpp
@@ -15,6 +15,8 @@ * and limitations under the License. * ------------------------------------------------------------------- */ +#include "log/log.h" + #include "mp4dec_lib.h" #include "bitstream.h" #include "vlc_decode.h" @@ -1336,8 +1338,7 @@ } tmpvar = BitstreamReadBits16(stream, 9); - video->displayWidth = (tmpvar + 1) << 2; - video->width = (video->displayWidth + 15) & -16; + int tmpDisplayWidth = (tmpvar + 1) << 2; /* marker bit */ if (!BitstreamRead1Bits(stream)) { @@ -1350,14 +1351,21 @@ status = PV_FAIL; goto return_point; } - video->displayHeight = tmpvar << 2; - video->height = (video->displayHeight + 15) & -16; + int tmpDisplayHeight = tmpvar << 2; + int tmpHeight = (tmpDisplayHeight + 15) & -16; + int tmpWidth = (tmpDisplayWidth + 15) & -16; - if (video->height * video->width > video->size) + if (tmpHeight * tmpWidth > video->size) { + // This is just possibly "b/37079296". + ALOGE("b/37079296"); status = PV_FAIL; goto return_point; } + video->displayWidth = tmpDisplayWidth; + video->width = tmpWidth; + video->displayHeight = tmpDisplayHeight; + video->height = tmpHeight; video->nTotalMB = video->width / MB_SIZE * video->height / MB_SIZE;