Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/native/crt.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ jobject aws_jni_direct_byte_buffer_from_raw_ptr(JNIEnv *env, const void *dst, si
if (jByteBuf) {
aws_jni_byte_buffer_set_limit(env, jByteBuf, (jint)capacity);
aws_jni_byte_buffer_set_position(env, jByteBuf, 0);
} else {
if (aws_jni_check_and_clear_exception(env)) {
(void)aws_raise_error(AWS_ERROR_HTTP_CALLBACK_FAILURE);
}
}

return jByteBuf;
Expand Down
34 changes: 25 additions & 9 deletions src/native/http_request_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,37 @@ static int s_aws_input_stream_read(struct aws_input_stream *stream, struct aws_b
}

size_t out_remaining = dest->capacity - dest->len;
int result = AWS_OP_SUCCESS;
/* Newer updates allow part sizes up to 5GB. Since number of bytes required for a 5GB part is
greater than INT_MAX, it would cause a bug where the java does not allocate memory and return a null buffer
since Java natively does not support direct allocation of buffers of capacity > Integer.MAX_VALUE. */
while (out_remaining > 0) {
size_t chunk_size = INT_MAX;
if (out_remaining <= chunk_size) {
chunk_size = out_remaining;
}

jobject direct_buffer = aws_jni_direct_byte_buffer_from_raw_ptr(env, dest->buffer + dest->len, out_remaining);
jobject direct_buffer = aws_jni_direct_byte_buffer_from_raw_ptr(env, dest->buffer + dest->len, chunk_size);
Comment thread
azkrishpy marked this conversation as resolved.
Outdated

impl->body_done = (*env)->CallBooleanMethod(
env, impl->http_request_body_stream, http_request_body_stream_properties.send_outgoing_body, direct_buffer);
impl->body_done = (*env)->CallBooleanMethod(
env, impl->http_request_body_stream, http_request_body_stream_properties.send_outgoing_body, direct_buffer);

if (aws_jni_check_and_clear_exception(env)) {
result = aws_raise_error(AWS_ERROR_HTTP_CALLBACK_FAILURE);
(*env)->DeleteLocalRef(env, direct_buffer);
break;
}

int result = AWS_OP_SUCCESS;
if (aws_jni_check_and_clear_exception(env)) {
result = aws_raise_error(AWS_ERROR_HTTP_CALLBACK_FAILURE);
} else {
size_t amt_written = aws_jni_byte_buffer_get_position(env, direct_buffer);
if (amt_written == 0) {
(*env)->DeleteLocalRef(env, direct_buffer);
break;
}
dest->len += amt_written;
}
out_remaining -= amt_written;

(*env)->DeleteLocalRef(env, direct_buffer);
(*env)->DeleteLocalRef(env, direct_buffer);
}

aws_jni_release_thread_env(impl->jvm, &jvm_env_context);
/********** JNI ENV RELEASE **********/
Expand Down
Loading
Loading