Merge cherrypicks of [4986743, 4986744, 4987539, 4987168, 4986376, 4986377, 4986378, 4986889, 4986745, 4986746, 4986747, 4986748, 4986749, 4986750, 4986773, 4987169, 4987170, 4987611, 4987631, 4987632, 4987633, 4987634, 4986890, 4987612, 4987651, 4987598, 4987613, 4987614, 4987615, 4987599, 4986379, 4986380, 4987652, 4987653, 4987691, 4986774] into pi-qpr1-release

Change-Id: I831fff0ac8b4aaeebea8dd608aa78b4127f7afaf
diff --git a/arm-wt-22k/lib_src/eas_public.c b/arm-wt-22k/lib_src/eas_public.c
index eb41113..19481b5 100644
--- a/arm-wt-22k/lib_src/eas_public.c
+++ b/arm-wt-22k/lib_src/eas_public.c
@@ -1247,12 +1247,13 @@
     EAS_BOOL done;
     EAS_INT yieldCount = YIELD_EVENT_COUNT;
     EAS_U32 time = 0;
+
     // This constant is the maximum number of events that can be processed in a single time slice.
     // A typical ringtone will contain a few events per time slice.
     // Extremely dense ringtones might go up to 50 events.
     // If we see this many events then the file is probably stuck in an infinite loop
-    // and should be aborted.  In our testing, it took less than 100 msec to hit this limit.
-    static const EAS_INT MAX_EVENT_COUNT = 50000;
+    // and should be aborted.
+    static const EAS_INT MAX_EVENT_COUNT = 100000;
     EAS_INT eventCount = 0;
 
     /* does this parser have a time function? */
@@ -1308,10 +1309,14 @@
                         return result;
                     }
                 }
-                // An infinite loop within a single frame of a ringtone file can cause this function
+
+                // An infinite loop within a ringtone file can cause this function
                 // to loop forever.  Try to detect that and return an error.
-                if (++eventCount >= MAX_EVENT_COUNT) {
-                    ALOGE("%s() aborting, %d events without advancing to next frame",
+                // Only check when playing. Otherwise a very large file could be rejected
+                // when scanning the entire file in a single call to this function.
+                // OTA files will only do infinite loops when in eParserModePlay.
+                if (++eventCount >= MAX_EVENT_COUNT && parseMode == eParserModePlay) {
+                    ALOGE("%s() aborting, %d events. Infinite loop in song file?!",
                             __func__, eventCount);
                     android_errorWriteLog(0x534e4554, "68664359");
                     return EAS_ERROR_FILE_POS;