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

Side by Side Diff: src/core/SkMatrix.cpp

Issue 41253002: Checking structure sizes before reading them from memory to avoid overflowing the buffer's stream. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkMatrix.h" 8 #include "SkMatrix.h"
9 #include "Sk64.h" 9 #include "Sk64.h"
10 #include "SkFloatBits.h" 10 #include "SkFloatBits.h"
(...skipping 1903 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, 1914 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax,
1915 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax); 1915 SK_ScalarMax, SK_ScalarMax, SK_ScalarMax);
1916 gInvalid.getType(); // force the type to be computed 1916 gInvalid.getType(); // force the type to be computed
1917 gOnce = true; 1917 gOnce = true;
1918 } 1918 }
1919 return gInvalid; 1919 return gInvalid;
1920 } 1920 }
1921 1921
1922 /////////////////////////////////////////////////////////////////////////////// 1922 ///////////////////////////////////////////////////////////////////////////////
1923 1923
1924 uint32_t SkMatrix::sizeInMemory() const {
1925 return SizeToRead(); // This is a constant for SkMatrix
1926 }
1927
1928 uint32_t SkMatrix::SizeToRead() {
1929 return 9 * sizeof(SkScalar);
1930 }
1931
1924 uint32_t SkMatrix::writeToMemory(void* buffer) const { 1932 uint32_t SkMatrix::writeToMemory(void* buffer) const {
1925 // TODO write less for simple matrices 1933 // TODO write less for simple matrices
1926 if (buffer) { 1934 if (buffer) {
1927 memcpy(buffer, fMat, 9 * sizeof(SkScalar)); 1935 memcpy(buffer, fMat, sizeInMemory());
1928 } 1936 }
1929 return 9 * sizeof(SkScalar); 1937 return sizeInMemory();
1930 } 1938 }
1931 1939
1932 uint32_t SkMatrix::readFromMemory(const void* buffer) { 1940 uint32_t SkMatrix::readFromMemory(const void* buffer) {
1933 if (buffer) { 1941 if (buffer) {
1934 memcpy(fMat, buffer, 9 * sizeof(SkScalar)); 1942 memcpy(fMat, buffer, SizeToRead());
1935 this->setTypeMask(kUnknown_Mask); 1943 this->setTypeMask(kUnknown_Mask);
1936 } 1944 }
1937 return 9 * sizeof(SkScalar); 1945 return sizeInMemory();
1938 } 1946 }
1939 1947
1940 #ifdef SK_DEVELOPER 1948 #ifdef SK_DEVELOPER
1941 void SkMatrix::dump() const { 1949 void SkMatrix::dump() const {
1942 SkString str; 1950 SkString str;
1943 this->toString(&str); 1951 this->toString(&str);
1944 SkDebugf("%s\n", str.c_str()); 1952 SkDebugf("%s\n", str.c_str());
1945 } 1953 }
1946 1954
1947 void SkMatrix::toString(SkString* str) const { 1955 void SkMatrix::toString(SkString* str) const {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
2103 rotation1->fX = cos1; 2111 rotation1->fX = cos1;
2104 rotation1->fY = sin1; 2112 rotation1->fY = sin1;
2105 } 2113 }
2106 if (NULL != rotation2) { 2114 if (NULL != rotation2) {
2107 rotation2->fX = cos2; 2115 rotation2->fX = cos2;
2108 rotation2->fY = sin2; 2116 rotation2->fY = sin2;
2109 } 2117 }
2110 2118
2111 return true; 2119 return true;
2112 } 2120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698