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

Commit 57f790f9 authored by Andreas Huber's avatar Andreas Huber
Browse files

If we never triggered a range request but know the content length make sure to...

If we never triggered a range request but know the content length make sure to not read more data than there could be, otherwise we'd block indefinitely if the server doesn't close the connection.

related-to-bug: 2442307
parent 24137908
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -14,6 +14,10 @@
 * limitations under the License.
 */

//#define LOG_NDEBUG 0
#define LOG_TAG "HTTPDataSource"
#include <utils/Log.h>

#include "include/stagefright_string.h"
#include "include/HTTPStream.h"

@@ -266,6 +270,8 @@ ssize_t HTTPDataSource::sendRangeRequest(size_t offset) {
}

ssize_t HTTPDataSource::readAt(off_t offset, void *data, size_t size) {
    LOGV("readAt %ld, size %d", offset, size);

    if (offset >= mBufferOffset
            && offset < (off_t)(mBufferOffset + mBufferLength)) {
        size_t num_bytes_available = mBufferLength - (offset - mBufferOffset);
@@ -298,6 +304,15 @@ ssize_t HTTPDataSource::readAt(off_t offset, void *data, size_t size) {

    mBufferOffset = offset;

    if (mContentLengthValid
            && mBufferOffset + contentLength >= mContentLength) {
        // If we never triggered a range request but know the content length,
        // make sure to not read more data than there could be, otherwise
        // we'd block indefinitely if the server doesn't close the connection.

        contentLength = mContentLength - mBufferOffset;
    }

    if (contentLength <= 0) {
        return contentLength;
    }
+2 −2
Original line number Diff line number Diff line
@@ -276,11 +276,11 @@ ssize_t HTTPStream::receive(void *data, size_t size) {
            }

            disconnect();
            return total == 0 ? ERROR_IO : total;
            return total == 0 ? (ssize_t)ERROR_IO : total;
        } else if (n == 0) {
            disconnect();

            return total == 0 ? ERROR_CONNECTION_LOST : total;
            return total == 0 ? (ssize_t)ERROR_CONNECTION_LOST : total;
        }

        total += (size_t)n;