Merge lp:~julian-edwards/gwacl/extra-putpage-checks into lp:gwacl

Proposed by Julian Edwards
Status: Merged
Approved by: Julian Edwards
Approved revision: 132
Merged at revision: 131
Proposed branch: lp:~julian-edwards/gwacl/extra-putpage-checks
Merge into: lp:gwacl
Diff against target: 106 lines (+33/-5)
2 files modified
storage_base.go (+9/-0)
storage_base_test.go (+24/-5)
To merge this branch: bzr merge lp:~julian-edwards/gwacl/extra-putpage-checks
Reviewer Review Type Date Requested Status
Gavin Panella Approve
Review via email: mp+171008@code.launchpad.net

Commit message

When dealing with page blobs, make sure any sizes and ranges are aligned to 512 byte boundaries.

Description of the change

Add more consistency checks around dealing with page blobs. We have to make sure any sizes and ranges are aligned to 512 byte boundaries.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

Looks good. Couple of points.

[1]

+            return fmt.Errorf("Size must be multiple of 512 bytes")

*a* multiple?

Here and in one other place.

[2]

+    validStart := math.Mod(float64(req.StartRange), 512) == 0

There is a % operator in Go:

    validStart := (req.StartRange % 512 == 0)

review: Approve
Revision history for this message
Julian Edwards (julian-edwards) wrote :

On 24/06/13 18:31, Gavin Panella wrote:
> Review: Approve
>
> Looks good. Couple of points.
>
>
> [1]
>
> + return fmt.Errorf("Size must be multiple of 512 bytes")
>
> *a* multiple?
>
> Here and in one other place.

Omitting prepositions is perfectly normal English, but I will assuage
your concerns.

>
>
> [2]
>
> + validStart := math.Mod(float64(req.StartRange), 512) == 0
>
> There is a % operator in Go:
>
> validStart := (req.StartRange % 512 == 0)
>

Feck. Sometimes you look past the bleedin' obvious when a language
teaches you that you can't rely on the obvious.

Thanks!

132. By Julian Edwards

gavin's review comments

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'storage_base.go'
2--- storage_base.go 2013-06-24 14:05:24 +0000
3+++ storage_base.go 2013-06-25 00:24:24 +0000
4@@ -439,6 +439,9 @@
5 if req.Size == 0 {
6 return fmt.Errorf("Must supply a size for a page blob")
7 }
8+ if req.Size % 512 != 0 {
9+ return fmt.Errorf("Size must be a multiple of 512 bytes")
10+ }
11 case "block":
12 blobType = "BlockBlob"
13 default:
14@@ -477,6 +480,12 @@
15 // Send a request to add a range of data into a page blob.
16 // See http://msdn.microsoft.com/en-us/library/windowsazure/ee691975.aspx
17 func (context *StorageContext) PutPage(req *PutPageRequest) error {
18+ validStart := (req.StartRange % 512) == 0
19+ validEnd := (req.EndRange % 512) == 511
20+ if !(validStart && validEnd) {
21+ return fmt.Errorf(
22+ "StartRange must be a multiple of 512, EndRange must be one less than a multiple of 512")
23+ }
24 uri := addURLQueryParams(
25 context.GetFileURL(req.Container, req.Filename),
26 "comp", "page")
27
28=== modified file 'storage_base_test.go'
29--- storage_base_test.go 2013-06-24 11:25:25 +0000
30+++ storage_base_test.go 2013-06-25 00:24:24 +0000
31@@ -664,7 +664,7 @@
32
33 err := context.PutPage(&PutPageRequest{
34 Container: "container", Filename: "filename", StartRange: 0,
35- EndRange: 512, Data: dataReader})
36+ EndRange: 511, Data: dataReader})
37 c.Assert(err, IsNil)
38
39 // Ensure that container was set right.
40@@ -672,7 +672,7 @@
41 // Ensure that the Authorization header is set.
42 c.Check(transport.Request.Header.Get("Authorization"), Not(Equals), "")
43 // Check the range is set.
44- c.Check(transport.Request.Header.Get("x-ms-range"), Equals, "bytes=0-512")
45+ c.Check(transport.Request.Header.Get("x-ms-range"), Equals, "bytes=0-511")
46 // Check special page write header.
47 c.Check(transport.Request.Header.Get("x-ms-page-write"), Equals, "update")
48 // "?comp=page" should be part of the URL.
49@@ -691,7 +691,7 @@
50 context := makeStorageContext(&TestTransport{Error: cannedError})
51 err := context.PutPage(&PutPageRequest{
52 Container: "container", Filename: "filename", StartRange: 0,
53- EndRange: 512, Data: nil})
54+ EndRange: 511, Data: nil})
55 c.Assert(err, NotNil)
56 }
57
58@@ -702,7 +702,7 @@
59 context := makeStorageContext(&TestTransport{Response: response})
60 err := context.PutPage(&PutPageRequest{
61 Container: "container", Filename: "filename", StartRange: 0,
62- EndRange: 512, Data: nil})
63+ EndRange: 511, Data: nil})
64 c.Assert(err, NotNil)
65 c.Check(err, ErrorMatches, ".*102.*")
66 c.Check(err, ErrorMatches, ".*Frotzed.*")
67@@ -716,12 +716,21 @@
68 context := makeStorageContext(&TestTransport{Response: response})
69 err := context.PutPage(&PutPageRequest{
70 Container: "container", Filename: "filename", StartRange: 0,
71- EndRange: 512, Data: nil})
72+ EndRange: 511, Data: nil})
73 serverError, ok := err.(*ServerError)
74 c.Check(ok, Equals, true)
75 c.Check(serverError.HTTPStatus.StatusCode(), Equals, http.StatusNotFound)
76 }
77
78+// Range values outside the limits should get rejected.
79+func (suite *TestPutPage) TestRangeLimits(c *C) {
80+ context := makeStorageContext(&TestTransport{})
81+ err := context.PutPage(&PutPageRequest{
82+ StartRange: 513, EndRange: 555})
83+ c.Assert(err, NotNil)
84+ c.Check(err, ErrorMatches, ".*StartRange must be a multiple of 512, EndRange must be one less than a multiple of 512.*")
85+}
86+
87 type TestPutBlob struct{}
88
89 var _ = Suite(&TestPutBlob{})
90@@ -764,6 +773,16 @@
91 c.Assert(err, ErrorMatches, "Must supply a size for a page blob")
92 }
93
94+// PutBlob for a page should return an error when Size is not a multiple
95+// of 512 bytes.
96+func (suite *TestPutBlob) TestPutPageBlobWithInvalidSiuze(c *C) {
97+ context := makeStorageContext(&TestTransport{})
98+ err := context.PutBlob(&PutBlobRequest{
99+ Container: "container", BlobType: "page", Filename: "blob",
100+ Size: 1015})
101+ c.Assert(err, ErrorMatches, "Size must be a multiple of 512 bytes")
102+}
103+
104 // Passing a BlobType other than page or block results in a panic.
105 func (suite *TestPutBlob) TestBlobType(c *C) {
106 defer func() {

Subscribers

People subscribed via source and target branches

to all changes: