Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: don't use req.Marshal to encode a binary payload… #110

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions storage/2023-11-03/blob/blobs/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package blobs
import (
"context"
"fmt"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -65,14 +66,15 @@ func (c Client) Get(ctx context.Context, containerName, blobName string, input G
var resp *client.Response
resp, err = req.Execute(ctx)
if resp != nil {
result.Contents = &[]byte{}
result.HttpResponse = resp.Response

err = resp.Unmarshal(result.Contents)
respBody, err := io.ReadAll(resp.Body)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's possible for resp.Body to be nil here fwiw, so this is a potential crash-point:

Suggested change
respBody, err := io.ReadAll(resp.Body)
var respBody io.Reader
if resp.Body != nil {
respBody, err = io.ReadAll(resp.Body)

if err != nil {
err = fmt.Errorf("unmarshalling response: %+v", err)
return
return result, fmt.Errorf("could not parse response body")
}
resp.Body.Close()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resp.Body.Close()
respBody.Close()
}


result.Contents = &respBody
}
if err != nil {
err = fmt.Errorf("executing request: %+v", err)
Expand Down
9 changes: 5 additions & 4 deletions storage/2023-11-03/blob/blobs/put_block_blob.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package blobs

import (
"bytes"
"context"
"fmt"
"io"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -78,10 +80,9 @@ func (c Client) PutBlockBlob(ctx context.Context, containerName, blobName string
return
}

err = req.Marshal(input.Content)
if err != nil {
err = fmt.Errorf("marshalling request: %+v", err)
return
if input.Content != nil {
req.ContentLength = int64(len(*input.Content))
req.Body = io.NopCloser(bytes.NewReader(*input.Content))
}

var resp *client.Response
Expand Down
Loading