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

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 2528243002: Fix silent truncations when extracting values from CheckedNumeric (Closed)
Patch Set: compile cleanup and fix Created 4 years 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 7999 matching lines...) Expand 10 before | Expand all | Expand 10 after
8010 base::CheckedNumeric<GLint> src_width_temp = srcX1; 8010 base::CheckedNumeric<GLint> src_width_temp = srcX1;
8011 src_width_temp -= srcX0; 8011 src_width_temp -= srcX0;
8012 base::CheckedNumeric<GLint> src_height_temp = srcY1; 8012 base::CheckedNumeric<GLint> src_height_temp = srcY1;
8013 src_height_temp -= srcY0; 8013 src_height_temp -= srcY0;
8014 GLuint src_width = 0, src_height = 0; 8014 GLuint src_width = 0, src_height = 0;
8015 if (!src_width_temp.IsValid() || !src_height_temp.IsValid()) { 8015 if (!src_width_temp.IsValid() || !src_height_temp.IsValid()) {
8016 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name, 8016 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name,
8017 "the width or height of src region overflow"); 8017 "the width or height of src region overflow");
8018 return; 8018 return;
8019 } 8019 }
8020 src_width = std::abs(src_width_temp.ValueOrDefault(0)); 8020 if (!src_width_temp.Abs().AssignIfValid(&src_width))
8021 src_height = std::abs(src_height_temp.ValueOrDefault(0)); 8021 src_width = 0;
8022 if (!src_height_temp.Abs().AssignIfValid(&src_height))
8023 src_height = 0;
8022 8024
8023 gfx::Rect src_region(src_x, src_y, src_width, src_height); 8025 gfx::Rect src_region(src_x, src_y, src_width, src_height);
8024 if (!src_bounds.Contains(src_region) && 8026 if (!src_bounds.Contains(src_region) &&
8025 (src_width != 0) && (src_height != 0)) { 8027 (src_width != 0) && (src_height != 0)) {
8026 // If pixels lying outside the read framebuffer, adjust src region 8028 // If pixels lying outside the read framebuffer, adjust src region
8027 // and dst region to appropriate in-bounds regions respectively. 8029 // and dst region to appropriate in-bounds regions respectively.
8028 src_bounds.Intersect(src_region); 8030 src_bounds.Intersect(src_region);
8029 GLuint src_real_width = src_bounds.width(); 8031 GLuint src_real_width = src_bounds.width();
8030 GLuint src_real_height = src_bounds.height(); 8032 GLuint src_real_height = src_bounds.height();
8031 GLuint xoffset = src_bounds.x() - src_x; 8033 GLuint xoffset = src_bounds.x() - src_x;
(...skipping 14 matching lines...) Expand all
8046 base::CheckedNumeric<GLint> dst_width_temp = dstX1; 8048 base::CheckedNumeric<GLint> dst_width_temp = dstX1;
8047 dst_width_temp -= dstX0; 8049 dst_width_temp -= dstX0;
8048 base::CheckedNumeric<GLint> dst_height_temp = dstY1; 8050 base::CheckedNumeric<GLint> dst_height_temp = dstY1;
8049 dst_height_temp -= dstY0; 8051 dst_height_temp -= dstY0;
8050 GLuint dst_width = 0, dst_height = 0; 8052 GLuint dst_width = 0, dst_height = 0;
8051 if (!dst_width_temp.IsValid() || !dst_height_temp.IsValid()) { 8053 if (!dst_width_temp.IsValid() || !dst_height_temp.IsValid()) {
8052 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name, 8054 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, func_name,
8053 "the width or height of dst region overflow"); 8055 "the width or height of dst region overflow");
8054 return; 8056 return;
8055 } 8057 }
8056 dst_width = std::abs(dst_width_temp.ValueOrDefault(0)); 8058 if (dst_width_temp.Abs().AssignIfValid(&dst_width))
8057 dst_height = std::abs(dst_height_temp.ValueOrDefault(0)); 8059 dst_width = 0;
8060 if (dst_height_temp.Abs().AssignIfValid(&dst_height))
8061 dst_height = 0;
8058 8062
8059 GLfloat dst_mapping_width = 8063 GLfloat dst_mapping_width =
8060 static_cast<GLfloat>(src_real_width) * dst_width / src_width; 8064 static_cast<GLfloat>(src_real_width) * dst_width / src_width;
8061 GLfloat dst_mapping_height = 8065 GLfloat dst_mapping_height =
8062 static_cast<GLfloat>(src_real_height) * dst_height / src_height; 8066 static_cast<GLfloat>(src_real_height) * dst_height / src_height;
8063 GLfloat dst_mapping_xoffset = 8067 GLfloat dst_mapping_xoffset =
8064 static_cast<GLfloat>(xoffset) * dst_width / src_width; 8068 static_cast<GLfloat>(xoffset) * dst_width / src_width;
8065 GLfloat dst_mapping_yoffset = 8069 GLfloat dst_mapping_yoffset =
8066 static_cast<GLfloat>(yoffset) * dst_height / src_height; 8070 static_cast<GLfloat>(yoffset) * dst_height / src_height;
8067 8071
(...skipping 10797 matching lines...) Expand 10 before | Expand all | Expand 10 after
18865 } 18869 }
18866 18870
18867 // Include the auto-generated part of this file. We split this because it means 18871 // Include the auto-generated part of this file. We split this because it means
18868 // we can easily edit the non-auto generated parts right here in this file 18872 // we can easily edit the non-auto generated parts right here in this file
18869 // instead of having to edit some template or the code generator. 18873 // instead of having to edit some template or the code generator.
18870 #include "base/macros.h" 18874 #include "base/macros.h"
18871 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 18875 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
18872 18876
18873 } // namespace gles2 18877 } // namespace gles2
18874 } // namespace gpu 18878 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698