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

Side by Side Diff: gpu/command_buffer/client/gles2_implementation.cc

Issue 2310243002: Supress integer-overflow in TexSubImage2D(3D)Impl (Closed)
Patch Set: check xoffset Created 4 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // A class to emulate GLES2 over command buffers. 5 // A class to emulate GLES2 over command buffers.
6 6
7 #include "gpu/command_buffer/client/gles2_implementation.h" 7 #include "gpu/command_buffer/client/gles2_implementation.h"
8 8
9 #include <GLES2/gl2.h> 9 #include <GLES2/gl2.h>
10 #include <GLES2/gl2ext.h> 10 #include <GLES2/gl2ext.h>
11 #include <GLES2/gl2extchromium.h> 11 #include <GLES2/gl2extchromium.h>
12 #include <GLES3/gl3.h> 12 #include <GLES3/gl3.h>
13 #include <stddef.h> 13 #include <stddef.h>
14 #include <stdint.h> 14 #include <stdint.h>
15 #include <algorithm> 15 #include <algorithm>
16 #include <map> 16 #include <map>
17 #include <set> 17 #include <set>
18 #include <sstream> 18 #include <sstream>
19 #include <string> 19 #include <string>
20 #include "base/atomic_sequence_num.h" 20 #include "base/atomic_sequence_num.h"
21 #include "base/compiler_specific.h" 21 #include "base/compiler_specific.h"
22 #include "base/numerics/safe_math.h"
22 #include "base/strings/string_split.h" 23 #include "base/strings/string_split.h"
23 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
24 #include "base/sys_info.h" 25 #include "base/sys_info.h"
25 #include "base/threading/thread_task_runner_handle.h" 26 #include "base/threading/thread_task_runner_handle.h"
26 #include "base/trace_event/memory_allocator_dump.h" 27 #include "base/trace_event/memory_allocator_dump.h"
27 #include "base/trace_event/memory_dump_manager.h" 28 #include "base/trace_event/memory_dump_manager.h"
28 #include "base/trace_event/process_memory_dump.h" 29 #include "base/trace_event/process_memory_dump.h"
29 #include "base/trace_event/trace_event.h" 30 #include "base/trace_event/trace_event.h"
30 #include "gpu/command_buffer/client/buffer_tracker.h" 31 #include "gpu/command_buffer/client/buffer_tracker.h"
31 #include "gpu/command_buffer/client/gles2_cmd_helper.h" 32 #include "gpu/command_buffer/client/gles2_cmd_helper.h"
(...skipping 2836 matching lines...) Expand 10 before | Expand all | Expand 10 after
2868 return; 2869 return;
2869 } 2870 }
2870 } else { 2871 } else {
2871 service_padded_row_size = padded_row_size; 2872 service_padded_row_size = padded_row_size;
2872 } 2873 }
2873 2874
2874 // advance pixels pointer past the skip rows and skip pixels 2875 // advance pixels pointer past the skip rows and skip pixels
2875 pixels = reinterpret_cast<const int8_t*>(pixels) + skip_size; 2876 pixels = reinterpret_cast<const int8_t*>(pixels) + skip_size;
2876 2877
2877 ScopedTransferBufferPtr buffer(size, helper_, transfer_buffer_); 2878 ScopedTransferBufferPtr buffer(size, helper_, transfer_buffer_);
2879 base::CheckedNumeric<GLint> checked_xoffset = xoffset;
2880 checked_xoffset += width;
2881 if (!checked_xoffset.IsValid()) {
2882 SetGLError(GL_INVALID_VALUE, "TexSubImage2D", "xoffset + width overflows");
2883 return;
2884 }
2885 base::CheckedNumeric<GLint> checked_yoffset = yoffset;
2886 checked_yoffset += height;
2887 if (!checked_yoffset.IsValid()) {
2888 SetGLError(GL_INVALID_VALUE, "TexSubImage2D", "yoffset + height overflows");
2889 return;
2890 }
2878 TexSubImage2DImpl( 2891 TexSubImage2DImpl(
2879 target, level, xoffset, yoffset, width, height, format, type, 2892 target, level, xoffset, yoffset, width, height, format, type,
2880 unpadded_row_size, pixels, padded_row_size, GL_FALSE, &buffer, 2893 unpadded_row_size, pixels, padded_row_size, GL_FALSE, &buffer,
2881 service_padded_row_size); 2894 service_padded_row_size);
2882 CheckGLError(); 2895 CheckGLError();
2883 } 2896 }
2884 2897
2885 void GLES2Implementation::TexSubImage3D( 2898 void GLES2Implementation::TexSubImage3D(
2886 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, 2899 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
2887 GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, 2900 GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
2993 return; 3006 return;
2994 } 3007 }
2995 } else { 3008 } else {
2996 service_padded_row_size = padded_row_size; 3009 service_padded_row_size = padded_row_size;
2997 } 3010 }
2998 3011
2999 // advance pixels pointer past the skip images/rows/pixels 3012 // advance pixels pointer past the skip images/rows/pixels
3000 pixels = reinterpret_cast<const int8_t*>(pixels) + skip_size; 3013 pixels = reinterpret_cast<const int8_t*>(pixels) + skip_size;
3001 3014
3002 ScopedTransferBufferPtr buffer(size, helper_, transfer_buffer_); 3015 ScopedTransferBufferPtr buffer(size, helper_, transfer_buffer_);
3016 base::CheckedNumeric<GLint> checked_xoffset = xoffset;
3017 checked_xoffset += width;
3018 if (!checked_xoffset.IsValid()) {
3019 SetGLError(GL_INVALID_VALUE, "TexSubImage3D", "xoffset + width overflows");
3020 return;
3021 }
3022 base::CheckedNumeric<GLint> checked_yoffset = yoffset;
3023 checked_yoffset += height;
3024 if (!checked_yoffset.IsValid()) {
3025 SetGLError(GL_INVALID_VALUE, "TexSubImage3D", "yoffset + height overflows");
3026 return;
3027 }
3028 base::CheckedNumeric<GLint> checked_zoffset = zoffset;
3029 checked_zoffset += depth;
3030 if (!checked_zoffset.IsValid()) {
3031 SetGLError(GL_INVALID_VALUE, "TexSubImage3D", "zoffset + depth overflows");
3032 return;
3033 }
3003 TexSubImage3DImpl( 3034 TexSubImage3DImpl(
3004 target, level, xoffset, yoffset, zoffset, width, height, depth, 3035 target, level, xoffset, yoffset, zoffset, width, height, depth,
3005 format, type, unpadded_row_size, pixels, padded_row_size, GL_FALSE, 3036 format, type, unpadded_row_size, pixels, padded_row_size, GL_FALSE,
3006 &buffer, service_padded_row_size); 3037 &buffer, service_padded_row_size);
3007 CheckGLError(); 3038 CheckGLError();
3008 } 3039 }
3009 3040
3010 static GLint ComputeNumRowsThatFitInBuffer(uint32_t padded_row_size, 3041 static GLint ComputeNumRowsThatFitInBuffer(uint32_t padded_row_size,
3011 uint32_t unpadded_row_size, 3042 uint32_t unpadded_row_size,
3012 unsigned int size, 3043 unsigned int size,
(...skipping 3882 matching lines...) Expand 10 before | Expand all | Expand 10 after
6895 cached_extensions_.clear(); 6926 cached_extensions_.clear();
6896 } 6927 }
6897 6928
6898 // Include the auto-generated part of this file. We split this because it means 6929 // Include the auto-generated part of this file. We split this because it means
6899 // we can easily edit the non-auto generated parts right here in this file 6930 // we can easily edit the non-auto generated parts right here in this file
6900 // instead of having to edit some template or the code generator. 6931 // instead of having to edit some template or the code generator.
6901 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" 6932 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h"
6902 6933
6903 } // namespace gles2 6934 } // namespace gles2
6904 } // namespace gpu 6935 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698