Skip to content

RequestBodyUtil.create uses inputStream.available() as contentLength #16006

@dantman

Description

@dantman

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

n/a

Bug

See: https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/modules/network/RequestBodyUtil.java#L132

RequestBodyUtil.create(MediaType mediaType, InputStream inputStream) uses inputStream.available() to set the contentLength of the RequestBody which is wrong.

https://developer.android.com/reference/java/io/InputStream.html#available()

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. The next invocation might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

Note that while some implementations of InputStream will return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugGood first issueInterested in collaborating? Take a stab at fixing one of these issues.Help Wanted :octocat:Issues ideal for external contributors.Resolution: LockedThis issue was locked by the bot.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions