@@ -94,21 +94,37 @@ static int s_aws_input_stream_read(struct aws_input_stream *stream, struct aws_b
9494 }
9595
9696 size_t out_remaining = dest -> capacity - dest -> len ;
97+ int result = AWS_OP_SUCCESS ;
98+ /* Newer updates allow part sizes up to 5GB. Since number of bytes required for a 5GB part is
99+ greater than INT_MAX, it would cause a bug where the java does not allocate memory and return a null buffer
100+ since Java natively does not support direct allocation of buffers of capacity > Integer.MAX_VALUE. */
101+ while (out_remaining > 0 ) {
102+ size_t chunk_size = INT_MAX ;
103+ if (out_remaining <= chunk_size ) {
104+ chunk_size = out_remaining ;
105+ }
97106
98- jobject direct_buffer = aws_jni_direct_byte_buffer_from_raw_ptr (env , dest -> buffer + dest -> len , out_remaining );
107+ jobject direct_buffer = aws_jni_direct_byte_buffer_from_raw_ptr (env , dest -> buffer + dest -> len , chunk_size );
99108
100- impl -> body_done = (* env )-> CallBooleanMethod (
101- env , impl -> http_request_body_stream , http_request_body_stream_properties .send_outgoing_body , direct_buffer );
109+ impl -> body_done = (* env )-> CallBooleanMethod (
110+ env , impl -> http_request_body_stream , http_request_body_stream_properties .send_outgoing_body , direct_buffer );
111+
112+ if (aws_jni_check_and_clear_exception (env )) {
113+ result = aws_raise_error (AWS_ERROR_HTTP_CALLBACK_FAILURE );
114+ (* env )-> DeleteLocalRef (env , direct_buffer );
115+ break ;
116+ }
102117
103- int result = AWS_OP_SUCCESS ;
104- if (aws_jni_check_and_clear_exception (env )) {
105- result = aws_raise_error (AWS_ERROR_HTTP_CALLBACK_FAILURE );
106- } else {
107118 size_t amt_written = aws_jni_byte_buffer_get_position (env , direct_buffer );
119+ if (amt_written == 0 ) {
120+ (* env )-> DeleteLocalRef (env , direct_buffer );
121+ break ;
122+ }
108123 dest -> len += amt_written ;
109- }
124+ out_remaining -= amt_written ;
110125
111- (* env )-> DeleteLocalRef (env , direct_buffer );
126+ (* env )-> DeleteLocalRef (env , direct_buffer );
127+ }
112128
113129 aws_jni_release_thread_env (impl -> jvm , & jvm_env_context );
114130 /********** JNI ENV RELEASE **********/
0 commit comments