Merge "Fix edge case when applying id3 unsynchronization" into lmp-dev am: 4c75797abd am: fea0a3bb6d am: f15220d4fc am: 7bccf8fae9 am: 31a2855f12 am: 46bc5d4f0b am: d65e5d3c22 am: 72748f4ee4 am: 6c73780bfe am: be5bb00900 am: 1924e48be2 am: e2e9ff9da0 am: 80cae0a651 am: a307668b1a
am: cdecce1475

Change-Id: I658d51528286ca79dbd457ec2b8fa90db63fbf23
diff --git a/media/libstagefright/id3/ID3.cpp b/media/libstagefright/id3/ID3.cpp
index 750f1de..61403be 100644
--- a/media/libstagefright/id3/ID3.cpp
+++ b/media/libstagefright/id3/ID3.cpp
@@ -392,7 +392,12 @@
                     --mSize;
                     --dataSize;
                 }
-                mData[writeOffset++] = mData[readOffset++];
+                if (i + 1 < dataSize) {
+                    // Only move data if there's actually something to move.
+                    // This handles the special case of the data being only [0xff, 0x00]
+                    // which should be converted to just 0xff if unsynchronization is on.
+                    mData[writeOffset++] = mData[readOffset++];
+                }
             }
             // move the remaining data following this frame
             if (readOffset <= oldSize) {