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

Commit a04e6fa6 authored by Daichi Hirono's avatar Daichi Hirono
Browse files

Fix MtpDevice to read 0-byte object correctly.

If a requested object is 0 bytes, the remote MTP device can return
MTP_CONTAINER_TYPE_RESPONSE at the first response package. Previous
implementation does not handle the case.

BUG=26317907

Change-Id: I6ae1138bf1b24aa197575bea0440cc032ffd622a
parent d958855f
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -659,6 +659,13 @@ bool MtpDevice::readObjectInternal(MtpObjectHandle handle,
        return false;
    }

    // If object size 0 byte, the remote device can reply response packet
    // without sending any data packets.
    if (mData.getContainerType() == MTP_CONTAINER_TYPE_RESPONSE) {
        mResponse.copyFrom(mData);
        return mResponse.getResponseCode() == MTP_RESPONSE_OK;
    }

    const uint32_t fullLength = mData.getContainerLength();
    if ((!expectedLength && fullLength < MTP_CONTAINER_HEADER_SIZE) ||
        (expectedLength && *expectedLength + MTP_CONTAINER_HEADER_SIZE != fullLength)) {