[automerger skipped] spdif: fix possible buffer overflow am: 1b72d76412 am: 86ca73cbd3 -s ours am: 32b99befb3 -s ours am: d7c086743a -s ours am: e8a7e84274 -s ours am: 11f5386fec -s ours am: 10b636389f -s ours am: 2652aae1f9 -s ours

am skip reason: Change-Id Ifc7f8c8946388e19f39f35d649a5936568f8b9b2 with SHA-1 762fbb3e09 is in history

Original change: https://googleplex-android-review.googlesource.com/c/platform/system/media/+/12638670

Change-Id: I6a20569487e681c8d3ba42fb29e59504370dbc2e
diff --git a/audio_utils/spdif/SPDIFEncoder.cpp b/audio_utils/spdif/SPDIFEncoder.cpp
index 4a8a02a..60b8425 100644
--- a/audio_utils/spdif/SPDIFEncoder.cpp
+++ b/audio_utils/spdif/SPDIFEncoder.cpp
@@ -140,6 +140,12 @@
         clearBurstBuffer();
         return;
     }
+
+    // Avoid reading first word past end of mBurstBuffer.
+    if (numBytes == 0) {
+        return;
+    }
+    // Pack bytes into short buffer.
     uint16_t pad = mBurstBuffer[mByteCursor >> 1];
     for (size_t i = 0; i < numBytes; i++) {
         if (mByteCursor & 1 ) {