Skip to content

bug: GCS writer double-encodes object paths, breaking write-then-read for keys with '/' #7926

Closed

Description

@chitralverma

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 for gcs_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: main at cdfd0b3a5, service gcs.
  • Not an emulator quirk: real GCS would also store the literal %2F name.
  • Fix: stop pre-encoding in the writer (pass &self.path raw at writer.rs:55 and :82, matching write_part/complete_part and 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

  1. added
    bug
    on Jul 20, 2026
  2. self-assigned this
    on Jul 20, 2026
  3. added
    releases-note/fix
    on Jul 20, 2026
  4. Xuanwo commented on Jul 21, 2026

    @Xuanwo
    Member

    I didn't understand this issue. How could the current implementation pass this test if the issue is valid?

    pub async fn test_write_with_special_chars(op: Operator) -> Result<()> {
    // Ignore test for vercel blob https://github.com/apache/opendal/pull/4103.
    #[cfg(feature = "services-vercel-blob")]
    if op.info().scheme() == services::VERCEL_BLOB_SCHEME {
    log::warn!("ignore test for vercel blob https://github.com/apache/opendal/pull/4103");
    return Ok(());
    }
    let path = format!("{} !@#$%^&()_+-=;',.txt", uuid::Uuid::new_v4());
    let (path, content, size) = TEST_FIXTURE.new_file_with_path(op.clone(), &path);
    op.write(&path, content).await?;
    let meta = op.stat(&path).await.expect("stat must succeed");
    assert_eq!(meta.content_length(), size as u64);
    Ok(())
    }

  5. Xuanwo commented on Jul 21, 2026

    @Xuanwo
    Member

    Oh, I got it. reqsign will re-build the request so the request after signing is already correct.

  6. Xuanwo commented on Jul 21, 2026

    @Xuanwo
    Member

    Maybe we should fix in reqsign first on this

  7. chitralverma commented on Jul 22, 2026

    @chitralverma
    ContributorAuthor

    Maybe we should fix in reqsign first on this

    Agreed on the diagnosis, and #784 captures it well. Just to close the loop on the two code paths:

    • write_once puts the object name in the query (?name=<path>). On the header-auth path, SigningRequest::build runs form_urlencoded::parse on the raw query (decoding name=odfs%252F… back to %2F) and apply writes the pairs back, so reqsign silently corrects the double-encode. That's why test_write_with_special_chars passes on real GCS.
    • Multipart (XML API) puts the object name in the URL path, which SigningRequest::build / apply pass through verbatim — no correction there. And with skip_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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugreleases-note/fixservices/gcs

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions