google-cloud-java icon indicating copy to clipboard operation
google-cloud-java copied to clipboard

Integer Overflow In BaseWriteChannel

Open Dima1224 opened this issue 10 years ago • 7 comments

Hi there. I'm testing out com.google.cloud.storage.Storage.writer() for writing to GCS. It works very well for files smaller than 2GB, but right around the 2GB mark WriteChannel throws an exception indicating that there's something wrong with the Content-Range header.

com.google.api.client.http.HttpResponseException: 400|Failed to parse Content-Range header.

I noticed that the Content-Range header is set in com.google.cloud.storage.spi.DefaultStorageRpc.write() and is calculated using com.google.cloud.BaseWriteChannel.position, which is an int. The problem is that at the 2GB mark the position variable overflows and becomes negative, causing panic and mayhem.

Here are some screenshots to paint a fuller picture:

trace1

trace2

Any chance we can get a patch for this? Should I submit a pull request?

Dima1224 avatar Nov 10 '16 18:11 Dima1224

Uh very sorry for the panic and mayhem. I believe we have fixed an analogous issue for the reader and this was left behind.

A PR would be awesome, it should be as simple as making position in BaseWriteChannel a long and changing the two getters position() and getPosition() to long as well. Let me know if you can make it, otherwise I'll kick one out ASAP.

mziccard avatar Nov 10 '16 18:11 mziccard

Can I ask you to do it? I don't have the code base checked out, was debugging against the sources jar.

Dima1224 avatar Nov 10 '16 18:11 Dima1224

Can I ask you to do it?

This is kind of my job so I'll be more than happy :D

mziccard avatar Nov 10 '16 18:11 mziccard

Looks like I'm talking to the right guy :)

Dima1224 avatar Nov 10 '16 19:11 Dima1224

Thanks! Any idea when the fix will be released?

Dima1224 avatar Nov 11 '16 14:11 Dima1224

@Dima1224 Beginning of next week the latest!

mziccard avatar Nov 11 '16 16:11 mziccard

Thanks for the lightning fast turnaround once again, @mziccard! Much appreciated.

Dima1224 avatar Nov 11 '16 16:11 Dima1224