Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 25f51c6a authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

NativeMIDI: Fix access to unaligned 64-bit data

Accessing unaligned 64-bit data in 32-bit ARM code leads
to SIGBUS / BUS_ADRALN fault. Since the timestamp position
in the message buffer is arbitrary, use memcpy to copy
it to the output argument.

Bug: 114123427
Test: 32-bit android.nativemidi.cts.NativeMidiEchoTest
Change-Id: I0cb08cb0b124e3f4a05ea19bf91f40081a584a2e
parent 78515967
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -338,7 +338,8 @@ public:
            numMessageBytes = std::min(maxBytes, numMessageBytes);
            memcpy(buffer, readBuffer + 1, numMessageBytes);
            if (timestampPtr != nullptr) {
                *timestampPtr = *(uint64_t*)(readBuffer + readCount - sizeof(uint64_t));
                memcpy(timestampPtr, readBuffer + readCount - sizeof(uint64_t),
                        sizeof(*timestampPtr));
            }
        }
        *numBytesReceivedPtr = numMessageBytes;