diff --git a/media/libstagefright/frameworks/av/media/libstagefright/SampleTable.cpp b/media/libstagefright/frameworks/av/media/libstagefright/SampleTable.cpp
index 9abc186..923b358 100644
--- a/media/libstagefright/frameworks/av/media/libstagefright/SampleTable.cpp
+++ b/media/libstagefright/frameworks/av/media/libstagefright/SampleTable.cpp
@@ -631,18 +631,18 @@ status_t
 SampleTable::parseSampleCencInfo() {
     if ((!mCencDefaultSize && !mCencInfoCount) || mCencOffsets.IsEmpty()) {
         // We don't have all the cenc information we need yet. Quietly fail and
         // hope we get the data we need later in the track header.
         ALOGV("Got half of cenc saio/saiz pair. Deferring parse until we get the other half.");
         return OK;
     }
 
-    if (!mCencSizes.IsEmpty() && mCencOffsets.Length() > 1 &&
-        mCencSizes.IsEmpty() != mCencOffsets.Length()) {
+    if ((mCencOffsets.Length() > 1 && mCencOffsets.Length() < mCencInfoCount) ||
+        (!mCencDefaultSize && mCencSizes.Length() < mCencInfoCount)) {
         return ERROR_MALFORMED;
     }
 
     if (mCencInfoCount > kMAX_ALLOCATION / sizeof(SampleCencInfo)) {
         // Avoid future OOM.
         return ERROR_MALFORMED;
     }

