Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: s3Client.copyObject not finding key when key contains spaces and plus signs #142

Open
dcheng1248 opened this issue Nov 28, 2024 · 1 comment

Comments

@dcheng1248
Copy link

dcheng1248 commented Nov 28, 2024

Hello,

The copyObject request does not work when the key contains spaces and plus signs. An ObjectNotExistException is thrown.

After looking into the source code, this happens because when the PUT request is made, the BucketData.objectMap sets the keys from the request that is without URL Encoding.

When a normal GET request is made, the BucketData.objectMap request gets the key from the request also without URL Encoding, so it works.

However, when a copyObject request is made, the source key and bucket are written to the x-amz-copy-source header and parsed in CopyObjectController.parseCopyOptions. Here the string includes URL Encoding and is not decoded before being passed to the CopyObjectService, which then passes the same key into the GetObjectService resulting in the exception.

Please let me know if you need more information. I would also be happy to submit a PR for the fix if needed.

Stack trace of exception:

28/Nov. 15:22:58.663 ERROR [defaultEventLoopGroup-4-4] com.robothy.netty.codec.HttpMessageHandler.channelRead0 - - - Failed to handle PUT file-with-encoding.xls: com.robothy.s3.core.exception.ObjectNotExistException: Object key ' file-with-encoding.xls' not exists. at com.robothy.s3.core.asserionts.ObjectAssertions.lambda$assertObjectExists$0(ObjectAssertions.java:18) at java.base/java.util.Optional.orElseThrow(Optional.java:403) at com.robothy.s3.core.asserionts.ObjectAssertions.assertObjectExists(ObjectAssertions.java:18) at com.robothy.s3.core.service.GetObjectService.getObjectFromUnVersionedBucket(GetObjectService.java:35) at com.robothy.s3.core.service.GetObjectService.getObject(GetObjectService.java:28) at com.robothy.s3.core.service.CopyObjectService.copyObject(CopyObjectService.java:26) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.base/java.lang.reflect.Method.invoke(Method.java:580) at com.robothy.s3.core.service.manager.LocalS3ServicesInvocationHandler.invoke(LocalS3ServicesInvocationHandler.java:38) at jdk.proxy5/jdk.proxy5.$Proxy123.copyObject(Unknown Source) at com.robothy.s3.rest.handler.CopyObjectController.handle(CopyObjectController.java:42) at com.robothy.netty.codec.HttpMessageHandler.channelRead0(HttpMessageHandler.java:46) at com.robothy.netty.codec.HttpMessageHandler.channelRead0(HttpMessageHandler.java:19) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) at io.netty.channel.AbstractChannelHandlerContext.access$600(AbstractChannelHandlerContext.java:61) at io.netty.channel.AbstractChannelHandlerContext$7.run(AbstractChannelHandlerContext.java:425) at io.netty.util.concurrent.AbstractEventExecutor.runTask$$$capture(AbstractEventExecutor.java:173) at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java) at io.netty.channel.DefaultEventLoop.run(DefaultEventLoop.java:54) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:994) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:1583)

@Robothy
Copy link
Owner

Robothy commented Nov 29, 2024

Thank you, @dcheng1248. Your analysis is correct. This issue can be addressed in the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants