Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Issue 37803002: Adding size parameter to read array functions (Closed)

Created:
7 years, 2 months ago by sugoi1
Modified:
7 years, 1 month ago
CC:
skia-review_googlegroups.com, DO NOT USE (jschuh)
Visibility:
Public.

Description

Adding size parameter to read array functions In some cases, the allocated array into which the data will be read is using getArrayCount() to allocate itself, which should be safe, but some cases use fixed length arrays or compute the array size before reading, which could overflow if the stream is compromised. To prevent that from happening, I added a check that will verify that the number of bytes to read will not exceed the capacity of the input buffer argument passed to all the read...Array() functions. I chose to use the byte array for this initial version, so that "size" represents the same value across all read...Array() functions, but I could also use the element count, if it is preferred. Note : readPointArray and writePointArray are unused, so I could also remove them BUG= Committed: http://code.google.com/p/skia/source/detail?r=12058

Patch Set 1 #

Total comments: 2

Patch Set 2 : Added dox in SkFlattenableBuffers.h #

Total comments: 2

Patch Set 3 : Added a better description for read...Array() functions #

Patch Set 4 : Bad upload, retrying #

Total comments: 6

Patch Set 5 : Fixed comments and added test #

Total comments: 2

Patch Set 6 : Fixed comments #

Patch Set 7 : More uint32_t to size_t changes #

Total comments: 1

Patch Set 8 : Sending read cursor to the end on error #

Patch Set 9 : Cleanup #

Total comments: 12

Patch Set 10 : Fixed comments #

Total comments: 5
Unified diffs Side-by-side diffs Delta from patch set Stats (+281 lines, -125 lines) Patch
M gyp/tests.gyp View 1 2 3 4 1 chunk +1 line, -0 lines 0 comments Download
M include/core/SkFlattenableBuffers.h View 1 2 3 4 5 6 7 8 9 2 chunks +19 lines, -6 lines 0 comments Download
M src/core/SkColorTable.cpp View 1 2 3 4 5 6 7 8 9 1 chunk +2 lines, -2 lines 0 comments Download
M src/core/SkFlattenableBuffers.cpp View 1 chunk +1 line, -1 line 2 comments Download
M src/core/SkMallocPixelRef.cpp View 1 chunk +1 line, -1 line 0 comments Download
M src/core/SkOrderedReadBuffer.h View 1 2 3 4 5 6 7 8 9 2 chunks +7 lines, -5 lines 0 comments Download
M src/core/SkOrderedReadBuffer.cpp View 1 2 3 4 5 6 7 8 9 1 chunk +23 lines, -24 lines 2 comments Download
src/core/SkValidatingReadBuffer.h View 1 2 3 4 5 6 7 8 9 1 chunk +9 lines, -9 lines 0 comments Download
M src/core/SkValidatingReadBuffer.cpp View 1 2 3 4 5 6 7 8 9 11 chunks +47 lines, -57 lines 0 comments Download
src/effects/SkBicubicImageFilter.cpp View 1 2 3 4 5 6 7 8 9 1 chunk +2 lines, -2 lines 0 comments Download
M src/effects/SkColorMatrixFilter.cpp View 1 2 3 4 5 6 7 8 9 1 chunk +1 line, -1 line 0 comments Download
M src/effects/SkDashPathEffect.cpp View 1 2 3 4 5 6 7 8 9 1 chunk +1 line, -1 line 0 comments Download
M src/effects/SkEmbossMaskFilter.cpp View 1 chunk +1 line, -1 line 0 comments Download
M src/effects/SkKernel33MaskFilter.cpp View 1 2 3 4 5 6 7 8 9 1 chunk +2 lines, -2 lines 0 comments Download
M src/effects/SkMatrixConvolutionImageFilter.cpp View 1 2 3 4 5 6 7 8 9 1 chunk +7 lines, -5 lines 0 comments Download
M src/effects/SkMergeImageFilter.cpp View 1 2 3 4 5 6 1 chunk +3 lines, -4 lines 0 comments Download
M src/effects/SkTableColorFilter.cpp View 1 chunk +1 line, -1 line 0 comments Download
M src/effects/SkTableMaskFilter.cpp View 1 chunk +1 line, -1 line 0 comments Download
M src/effects/gradients/SkGradientShader.cpp View 1 2 3 4 5 6 7 8 9 1 chunk +1 line, -1 line 0 comments Download
M src/images/SkImageRef.cpp View 1 chunk +1 line, -1 line 0 comments Download
A tests/SerializationTest.cpp View 1 2 3 4 5 6 7 8 9 1 chunk +150 lines, -0 lines 1 comment Download

Messages

Total messages: 28 (0 generated)
sugoi1
7 years, 2 months ago (2013-10-23 20:13:00 UTC) #1
reed1
https://codereview.chromium.org/37803002/diff/1/include/core/SkFlattenableBuffers.h File include/core/SkFlattenableBuffers.h (right): https://codereview.chromium.org/37803002/diff/1/include/core/SkFlattenableBuffers.h#newcode102 include/core/SkFlattenableBuffers.h:102: virtual uint32_t readByteArray(void* value, uint32_t size) = 0; Lets ...
7 years, 2 months ago (2013-10-23 21:10:10 UTC) #2
sugoi1
https://codereview.chromium.org/37803002/diff/1/include/core/SkFlattenableBuffers.h File include/core/SkFlattenableBuffers.h (right): https://codereview.chromium.org/37803002/diff/1/include/core/SkFlattenableBuffers.h#newcode102 include/core/SkFlattenableBuffers.h:102: virtual uint32_t readByteArray(void* value, uint32_t size) = 0; On ...
7 years, 2 months ago (2013-10-24 11:45:45 UTC) #3
reed1
https://codereview.chromium.org/37803002/diff/50001/include/core/SkFlattenableBuffers.h File include/core/SkFlattenableBuffers.h (right): https://codereview.chromium.org/37803002/diff/50001/include/core/SkFlattenableBuffers.h#newcode105 include/core/SkFlattenableBuffers.h:105: * the allocation size (in bytes) of the pointer ...
7 years, 2 months ago (2013-10-24 16:10:32 UTC) #4
sugoi1
https://codereview.chromium.org/37803002/diff/50001/include/core/SkFlattenableBuffers.h File include/core/SkFlattenableBuffers.h (right): https://codereview.chromium.org/37803002/diff/50001/include/core/SkFlattenableBuffers.h#newcode105 include/core/SkFlattenableBuffers.h:105: * the allocation size (in bytes) of the pointer ...
7 years, 2 months ago (2013-10-24 19:40:04 UTC) #5
reed1
https://codereview.chromium.org/37803002/diff/180001/include/core/SkFlattenableBuffers.h File include/core/SkFlattenableBuffers.h (right): https://codereview.chromium.org/37803002/diff/180001/include/core/SkFlattenableBuffers.h#newcode109 include/core/SkFlattenableBuffers.h:109: * If isValidating() is false, then the size parameter ...
7 years, 1 month ago (2013-10-29 19:39:42 UTC) #6
reed1
https://codereview.chromium.org/37803002/diff/180001/include/core/SkFlattenableBuffers.h File include/core/SkFlattenableBuffers.h (right): https://codereview.chromium.org/37803002/diff/180001/include/core/SkFlattenableBuffers.h#newcode111 include/core/SkFlattenableBuffers.h:111: virtual uint32_t readByteArray(void* value, uint32_t size) = 0; What ...
7 years, 1 month ago (2013-10-29 19:44:09 UTC) #7
sugoi1
https://codereview.chromium.org/37803002/diff/180001/include/core/SkFlattenableBuffers.h File include/core/SkFlattenableBuffers.h (right): https://codereview.chromium.org/37803002/diff/180001/include/core/SkFlattenableBuffers.h#newcode109 include/core/SkFlattenableBuffers.h:109: * If isValidating() is false, then the size parameter ...
7 years, 1 month ago (2013-10-29 20:04:50 UTC) #8
sugoi1
Fixed comments and added a test.
7 years, 1 month ago (2013-10-30 14:26:12 UTC) #9
reed1
https://codereview.chromium.org/37803002/diff/280001/include/core/SkFlattenableBuffers.h File include/core/SkFlattenableBuffers.h (right): https://codereview.chromium.org/37803002/diff/280001/include/core/SkFlattenableBuffers.h#newcode110 include/core/SkFlattenableBuffers.h:110: * If isValidating() is false, then the size parameter ...
7 years, 1 month ago (2013-10-30 14:50:30 UTC) #10
sugoi1
https://codereview.chromium.org/37803002/diff/280001/include/core/SkFlattenableBuffers.h File include/core/SkFlattenableBuffers.h (right): https://codereview.chromium.org/37803002/diff/280001/include/core/SkFlattenableBuffers.h#newcode110 include/core/SkFlattenableBuffers.h:110: * If isValidating() is false, then the size parameter ...
7 years, 1 month ago (2013-10-30 17:43:50 UTC) #11
reed1
The dox say that in the case of an error (size mismatch) the cursor will ...
7 years, 1 month ago (2013-10-30 17:50:11 UTC) #12
reed1
I propose we change readArray to always move the cursor to the end of the ...
7 years, 1 month ago (2013-10-30 17:59:54 UTC) #13
sugoi1
On 2013/10/30 17:50:11, reed1 wrote: > The dox say that in the case of an ...
7 years, 1 month ago (2013-10-30 18:12:51 UTC) #14
sugoi1
https://codereview.chromium.org/37803002/diff/350001/src/core/SkValidatingReadBuffer.cpp File src/core/SkValidatingReadBuffer.cpp (right): https://codereview.chromium.org/37803002/diff/350001/src/core/SkValidatingReadBuffer.cpp#newcode155 src/core/SkValidatingReadBuffer.cpp:155: (void)this->skip(sizeof(uint32_t)); // Skip array count Here, the reason why ...
7 years, 1 month ago (2013-10-30 18:14:32 UTC) #15
sugoi1
On 2013/10/30 17:59:54, reed1 wrote: > I propose we change readArray to always move the ...
7 years, 1 month ago (2013-10-30 18:19:47 UTC) #16
reed1
On 2013/10/30 18:19:47, sugoi1 wrote: > On 2013/10/30 17:59:54, reed1 wrote: > > I propose ...
7 years, 1 month ago (2013-10-30 18:36:49 UTC) #17
sugoi1
- Cleaned up the code by adding a few handy template functions - Hunted down ...
7 years, 1 month ago (2013-10-30 20:02:52 UTC) #18
reed1
lgtm w/ (future) nit about using templates when a local static function would do (which ...
7 years, 1 month ago (2013-10-30 20:22:31 UTC) #19
Stephen White
https://codereview.chromium.org/37803002/diff/500001/include/core/SkFlattenableBuffers.h File include/core/SkFlattenableBuffers.h (right): https://codereview.chromium.org/37803002/diff/500001/include/core/SkFlattenableBuffers.h#newcode114 include/core/SkFlattenableBuffers.h:114: virtual bool readByteArray(void* value, size_t size) = 0; Sorry ...
7 years, 1 month ago (2013-10-30 20:33:20 UTC) #20
reed1
On 2013/10/30 20:33:20, Stephen White wrote: > https://codereview.chromium.org/37803002/diff/500001/include/core/SkFlattenableBuffers.h > File include/core/SkFlattenableBuffers.h (right): > > https://codereview.chromium.org/37803002/diff/500001/include/core/SkFlattenableBuffers.h#newcode114 ...
7 years, 1 month ago (2013-10-30 21:05:28 UTC) #21
sugoi1
- Added tests for all read...Array() functions - Changed size parameter from size (in bytes) ...
7 years, 1 month ago (2013-10-31 14:16:23 UTC) #22
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://skia-tree-status.appspot.com/cq/sugoi@chromium.org/37803002/700001
7 years, 1 month ago (2013-10-31 14:33:21 UTC) #23
Stephen White
https://codereview.chromium.org/37803002/diff/700001/src/core/SkOrderedReadBuffer.cpp File src/core/SkOrderedReadBuffer.cpp (right): https://codereview.chromium.org/37803002/diff/700001/src/core/SkOrderedReadBuffer.cpp#newcode142 src/core/SkOrderedReadBuffer.cpp:142: if (count == size) { Nit: prefer the early-out ...
7 years, 1 month ago (2013-10-31 15:19:28 UTC) #24
commit-bot: I haz the power
Change committed as 12058
7 years, 1 month ago (2013-10-31 18:38:02 UTC) #25
Tom Sepez
https://codereview.chromium.org/37803002/diff/700001/src/core/SkFlattenableBuffers.cpp File src/core/SkFlattenableBuffers.cpp (right): https://codereview.chromium.org/37803002/diff/700001/src/core/SkFlattenableBuffers.cpp#newcode40 src/core/SkFlattenableBuffers.cpp:40: this->readByteArray(&proc, sizeof(void*)); drive-by: Code like this always scares the ...
7 years, 1 month ago (2013-11-08 20:59:00 UTC) #26
sugoi
https://codereview.chromium.org/37803002/diff/700001/src/core/SkFlattenableBuffers.cpp File src/core/SkFlattenableBuffers.cpp (right): https://codereview.chromium.org/37803002/diff/700001/src/core/SkFlattenableBuffers.cpp#newcode40 src/core/SkFlattenableBuffers.cpp:40: this->readByteArray(&proc, sizeof(void*)); On 2013/11/08 20:59:01, Tom Sepez wrote: > ...
7 years, 1 month ago (2013-11-08 21:31:15 UTC) #27
Tom Sepez
7 years, 1 month ago (2013-11-08 21:33:48 UTC) #28
Message was sent while issue was closed.
On 2013/11/08 21:31:15, sugoi wrote:
>
https://codereview.chromium.org/37803002/diff/700001/src/core/SkFlattenableBu...
> File src/core/SkFlattenableBuffers.cpp (right):
> 
>
https://codereview.chromium.org/37803002/diff/700001/src/core/SkFlattenableBu...
> src/core/SkFlattenableBuffers.cpp:40: this->readByteArray(&proc,
sizeof(void*));
> On 2013/11/08 20:59:01, Tom Sepez wrote:
> > drive-by: Code like this always scares the crap out of us, because although
it
> > looks like this may not get called in the inter-process case based upon
flags
> in
> > the current implementation, something might change introducing the easiest
> > possible escape ever. Please try to remove this and use another mechanism
even
> > in the intra-process case.
> > Besides, the code is not correct in that casting a function to void* is
wrong
> > per C specs (see e.g.
> > http://stackoverflow.com/questions/1096341/function-pointers-casting-in-c).
> 
> Thanks for your comment ! Yes, code like this was one of the main motivations
> for the rewrite of a new more secure serialization class in skia (see
> SkValidatingReadBuffer). The original serialization code in Skia was written
for
> speed, not for security, which is why it had to be redesigned and rewritten.
If
> performance allows it, maybe we could eventually modify Skia to only use the
> secure serialization, but there's still code using the old one for now (in
Skia,
> not in Chromium, AFAIK). Maybe we could find a way to make these functions
only
> accessible in Skia (as in #ifdefed out and not even compiled in Chrome, since
> Chrome will not use this). What do you think ?

Yes, #ifdefs are a good approach for now.  Thanks.

Powered by Google App Engine
This is Rietveld 408576698