fix: s3zip in fs mode (#13758)

The index was converted directly from bytes to binary. This would fail a roundtrip through json.

This would result in `Error: invalid input: magic number mismatch` when reading back.

On non-erasure backends store index as base64.
This commit is contained in:
Klaus Post 2021-11-25 09:11:25 -08:00 committed by GitHub
parent a5db4ca092
commit 34dc725d26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,7 @@ package cmd
import ( import (
"bytes" "bytes"
"context" "context"
"encoding/base64"
"errors" "errors"
"fmt" "fmt"
"io" "io"
@ -142,8 +143,15 @@ func (api objectAPIHandlers) getObjectInArchiveFileHandler(ctx context.Context,
var zipInfo []byte var zipInfo []byte
if z, ok := zipObjInfo.UserDefined[archiveInfoMetadataKey]; ok { if z, ok := zipObjInfo.UserDefined[archiveInfoMetadataKey]; ok {
zipInfo = []byte(z) if globalIsErasure {
} else { zipInfo = []byte(z)
} else {
zipInfo, err = base64.StdEncoding.DecodeString(z)
logger.LogIf(ctx, err)
// Will attempt to re-read...
}
}
if len(zipInfo) == 0 {
zipInfo, err = updateObjectMetadataWithZipInfo(ctx, objectAPI, bucket, zipPath, opts) zipInfo, err = updateObjectMetadataWithZipInfo(ctx, objectAPI, bucket, zipPath, opts)
} }
@ -151,7 +159,6 @@ func (api objectAPIHandlers) getObjectInArchiveFileHandler(ctx context.Context,
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL) writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL)
return return
} }
file, err := zipindex.FindSerialized(zipInfo, object) file, err := zipindex.FindSerialized(zipInfo, object)
if err != nil { if err != nil {
if err == io.EOF { if err == io.EOF {
@ -491,7 +498,11 @@ func updateObjectMetadataWithZipInfo(ctx context.Context, objectAPI ObjectLayer,
} }
srcInfo.UserDefined[archiveTypeMetadataKey] = archiveType srcInfo.UserDefined[archiveTypeMetadataKey] = archiveType
srcInfo.UserDefined[archiveInfoMetadataKey] = string(zipInfo) if globalIsErasure {
srcInfo.UserDefined[archiveInfoMetadataKey] = string(zipInfo)
} else {
srcInfo.UserDefined[archiveInfoMetadataKey] = base64.StdEncoding.EncodeToString(zipInfo)
}
srcInfo.metadataOnly = true srcInfo.metadataOnly = true
// Always update the same version id & modtime // Always update the same version id & modtime