Repository navigation
Description
Describe the bug
The GCS writer double-encodes object paths. GcsWriter::write_once and initiate_part pre-encode the path with gcs_percent_encode_path before calling into core, and gcs_insert_object_request / gcs_initiate_multipart_upload encode it again. A key like odfs/w/x.parquet is stored under the literal name odfs%2Fw%2Fx.parquet (the % gets re-encoded to %25).
The reader passes the raw path and encodes only once, so it looks for the correct name and gets 404. Result: every write-then-read of a key containing / fails.
- Writer pre-encodes:
core/services/gcs/src/writer.rs:55(write_once) and:82(initiate_part) - Core encodes again:
core/services/gcs/src/core.rs:271(gcs_insert_object_request), same forgcs_initiate_multipart_upload - Reader single-encodes (correct):
core/services/gcs/src/reader.rs:58->gcs_get_object_request(core.rs:168)
For multipart the two halves also disagree: initiate_part uses the double-encoded name while write_part/complete_part pass the raw path, so multipart uploads are internally inconsistent.
Steps to Reproduce
Reproduced against fsouza/fake-gcs-server with the Python binding built from main (cdfd0b3a5).
docker run -d --name fake-gcs -p 4443:4443 fsouza/fake-gcs-server:latest \
-scheme http -public-host localhost:4443 -port 4443
curl -s -X POST "http://localhost:4443/storage/v1/b?project=test" \
-H "Content-Type: application/json" -d '{"name":"test-bucket"}'import json, urllib.request, opendal
op = opendal.Operator("gcs", bucket="test-bucket",
endpoint="http://localhost:4443", skip_signature="true")
op.write("odfs/w/x.parquet", b"hello")
# What fake-gcs-server actually stored:
names = [i["name"] for i in json.load(urllib.request.urlopen(
"http://localhost:4443/storage/v1/b/test-bucket/o")).get("items", [])]
print(names) # ['odfs%2Fw%2Fx.parquet'] <- double-encoded
op.read("odfs/w/x.parquet") # raises NotFound (404)Output:
stored -> 'odfs%2Fw%2Fx.parquet'
read FAILED: NotFound (permanent) at read => Not Found
uri: http://localhost:4443/storage/v1/b/test-bucket/o/odfs%2Fw%2Fx.parquet?alt=media
Control: a key with no / (e.g. flatkey.parquet) round-trips fine, because there is nothing for the extra encode pass to corrupt.
Expected Behavior
odfs/w/x.parquet should be stored under the object name odfs/w/x.parquet and read back successfully, matching the reader's single-encode behavior. The path should be percent-encoded exactly once.
Additional Context
- Version:
mainatcdfd0b3a5, servicegcs. - Not an emulator quirk: real GCS would also store the literal
%2Fname. - Fix: stop pre-encoding in the writer (pass
&self.pathraw atwriter.rs:55and:82, matchingwrite_part/complete_partand the reader) and let core do the single canonical encode. Verified locally: with the pre-encode removed and the binding rebuilt, both single-shot and 9 MiB multipart writes store the correct nested name and read back.
Activity
Xuanwo commentedon Jul 21, 2026
I didn't understand this issue. How could the current implementation pass this test if the issue is valid?
opendal/core/tests/behavior/async_write.rs
Lines 114 to 131 in 2e9c10a
Xuanwo commentedon Jul 21, 2026
Oh, I got it. reqsign will re-build the request so the request after signing is already correct.
Xuanwo commentedon Jul 21, 2026
Maybe we should fix in reqsign first on this
chitralverma commentedon Jul 22, 2026
Agreed on the diagnosis, and #784 captures it well. Just to close the loop on the two code paths:
write_onceputs the object name in the query (?name=<path>). On the header-auth path,SigningRequest::buildrunsform_urlencoded::parseon the raw query (decodingname=odfs%252F…back to%2F) andapplywrites the pairs back, so reqsign silently corrects the double-encode. That's whytest_write_with_special_charspasses on real GCS.SigningRequest::build/applypass through verbatim — no correction there. And withskip_signature/allow_anonymous(fake-gcs, unsigned setups) reqsign never runs at all, so even the query case reaches the server double-encoded. That's the config I reproduced against.So the correction was accidental, path-specific, and signing-dependent — which is exactly the "callers can accidentally depend on reqsign rebuilding a URI during signing" case you called out in apache/reqsign#784.
As you noted there, #7927 is still the right fix since it removes the duplicate encoding before reqsign is involved, for both signed and unsigned setups. Happy to help with the Google signer portion of the #784 audit separately if useful.