awsdocs / aws-doc-sdk-examples

Welcome to the AWS Code Examples Repository. This repo contains code examples used in the AWS documentation, AWS SDK Developer Guides, and more. For more information, see the Readme.md file below.
Apache License 2.0
9.56k stars 5.63k forks source link

[Bug]: <AWSS3SigV4JavaSamples.zip has upload bug> #6799

Open sanhe-qigai opened 2 months ago

sanhe-qigai commented 2 months ago

Expected behavior

Hello, I found a bug in the package "AWSS3SigV4JavaSamples.zip". I downloaded this package from "https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-examples-using-sdks.html#sig-v4-examples-using-sdk-java". when i upload to s3 ,I use PutS3ObjectSample.java

Actual behavior

<?xml version="1.0" encoding="UTF-8"?>

XAmzContentSHA256MismatchThe provided 'x-amz-content-sha256' header does not match what was computed.2efb07c3c3e1b736f4e12f249f63976829ff012cd7ef40a70b6e3ee6344e12172dd6d43a7a0748921c3fffee5687a3f28b51ded41e00fbb98926919db9d3aca36FFBPMHDEJM59CRFMvcUeKbrglSYeu72DE825vxqyBPSOu85K8bn8NSCGe+Cp+tmyjSl5qzuvkSXOB/CI5J1ZLdy9fg=

Steps to reproduce

Specifically, in "HttpUtils.invokeHttpRequest", "wr.writeBytes(requestBody)" will cause the server to calculate hash256 incorrectly when the content contains Chinese characters.

Logs / stacktrace (if applicable)

It is recommended to change it to "wr.write(requestBody.getBytes(StandardCharsets.UTF_8))"

Which SDK were you using?

Java

Which OS were you using?

macOS

SDK version

No response

OS version

No response

scmacdon commented 1 month ago

This is not a code example issue. Looks like a S3 Doc issue. I will reassign.

sanhe-qigai commented 1 month ago

这不是代码示例问题。看起来像是 S3 Doc 问题。我会重新分配。

I would like to add that this should be a bug, because the char in JAVA is 16 bits, and one char stores one Chinese character. Directly converting it using the writeBytes method will become 8 bits, which directly causes the loss of the upper 8 bits. This leads to garbled Chinese characters.