Skip to content

fix(r2): tolerate missing httpMetadata/customMetadata on listed objects - #1098

Open
PedroRosalba wants to merge 1 commit into
cloudflare:mainfrom
PedroRosalba:fix/r2-list-optional-metadata
Open

PedroRosalba wants to merge 1 commit into
cloudflare:mainfrom
PedroRosalba:fix/r2-list-optional-metadata

Conversation

@PedroRosalba

Copy link
Copy Markdown

Problem

Since the r2_list_honor_include compatibility flag (2022-08-04), workerd only attaches httpMetadata and customMetadata to objects returned by bucket.list() when the listing asked for them through include. Both are optional in workers-types, but the worker-sys getters declare them required, so Object::http_metadata() panics in From<R2HttpMetadata> for HttpMetadata (unwrap of a TypeError reading contentType of undefined) and Object::custom_metadata() feeds undefined to Object.keys.

Fix

The getters return Option; http_metadata() yields an empty HttpMetadata and custom_metadata() an empty map when the runtime omitted the field. Public signatures are unchanged.

Tests

Miniflare's R2 backend still sends the fields as empty objects, so the committed test documents the behaviour on that shape and passes on main as well. The panic was reproduced by patching the local Miniflare backend to omit empty metadata, as production R2 does, and the fix was verified against that patched backend. The bug is visible in the workerd source for R2Bucket::list.

Tested on macOS (Apple Silicon) only.

Since the `r2_list_honor_include` compatibility flag (2022-08-04) workerd
only attaches `httpMetadata` and `customMetadata` to objects returned by
`bucket.list()` when the listing asked for them through `include`. Both
are optional in workers-types, but the worker-sys getters declared them
required, so `Object::http_metadata()` panicked in
`From<R2HttpMetadata> for HttpMetadata` (unwrap of a TypeError reading
`contentType` of `undefined`) and `Object::custom_metadata()` would feed
`undefined` to `Object.keys`.

The getters now return `Option`; `http_metadata()` yields an empty
`HttpMetadata` and `custom_metadata()` an empty map when the runtime
omitted the field. Public signatures are unchanged.

Miniflare's R2 backend still sends the fields as empty objects, so the new
test documents the behaviour on both shapes; the panic was reproduced by
making the backend omit empty metadata, as real R2 does.
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

Successfully merging this pull request may close these issues.

1 participant