Skip to content

Fix object store base64 encoding to keep url-safe padding - #58

Open
lifewcody wants to merge 1 commit into
thesis-php:0.4.xfrom
lifewcody:fix/object-store-base64-padding
Open

Fix object store base64 encoding to keep url-safe padding#58
lifewcody wants to merge 1 commit into
thesis-php:0.4.xfrom
lifewcody:fix/object-store-base64-padding

Conversation

@lifewcody

Copy link
Copy Markdown

While cross-testing an object store bucket between this client and nats.go I found that the two cannot see each other's objects.

Store::base64encode() strips the base64url padding when encoding an object name into the meta subject ($O.<store>.M.<name>) and when encoding the SHA-256 digest. The reference implementation keeps the padding in both places: encodeName() and GetObjectDigestValue() use base64.URLEncoding (the padded variant), and DecodeObjectDigest() decodes with the same strict codec, which errors on unpadded input. See jetstream/object.go (encodeName, GetObjectDigestValue, DecodeObjectDigest); the legacy object.go behaves the same.

The consequences, in both directions:

  • Objects written by this client are unreadable by nats.go. Even when the meta subject happens to match (name length divisible by 3), a SHA-256 digest is 32 bytes and its padded encoding always ends in =, so nats.go fails digest validation on every Get.
  • Objects written by nats.go cannot be looked up by this client whenever the encoded name requires padding, because info() queries the unpadded subject. Wildcard scans over $O.<store>.M.> still surface them, so they appear in listings but get() returns null.

The fix is to keep the padding, which matches nats.go byte for byte. I also added an assertion to testPutObject pinning the digest to the padded reference form (the existing xfile fixture already exercises a padding-requiring name).

One caveat, noted in the changelog: objects written by previous versions of this client live under unpadded meta subjects, so after this change they have to be re-put to be visible again. Since the store was not interoperable with other clients anyway, a clean cut seemed preferable to carrying a legacy fallback lookup, but happy to add one if you'd rather keep old buckets readable.

nats.go encodes object names in meta subjects and object digests with
padded url-safe base64 (base64.URLEncoding) and its digest decoder
rejects unpadded input. We stripped the padding, so objects written by
this client were unreadable by nats.go, and objects written by nats.go
could not be looked up here whenever the encoded name required padding.

Objects written by previous versions live under unpadded meta subjects
and have to be re-put after this fix.
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