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

Side by Side Diff: remoting/base/decoder_verbatim.cc

Issue 3388024: Fix memory problem in DecoderVerbatim (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Created 10 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
« no previous file with comments | « no previous file | remoting/base/decoder_verbatim_unittest.cc » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "remoting/base/decoder_verbatim.h" 5 #include "remoting/base/decoder_verbatim.h"
6 6
7 #include "remoting/base/protocol_util.h" 7 #include "remoting/base/protocol_util.h"
8 8
9 namespace remoting { 9 namespace remoting {
10 10
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 95 }
96 96
97 bool DecoderVerbatim::HandleRectData(ChromotingHostMessage* message) { 97 bool DecoderVerbatim::HandleRectData(ChromotingHostMessage* message) {
98 DCHECK_EQ(kWaitingForRectData, state_); 98 DCHECK_EQ(kWaitingForRectData, state_);
99 DCHECK_EQ(0, 99 DCHECK_EQ(0,
100 message->update_stream_packet().rect_data().sequence_number()); 100 message->update_stream_packet().rect_data().sequence_number());
101 101
102 // Copy the data line by line. 102 // Copy the data line by line.
103 const int src_stride = bytes_per_pixel_ * rect_width_; 103 const int src_stride = bytes_per_pixel_ * rect_width_;
104 const char* src = 104 const char* src =
105 message->update_stream_packet().rect_data().data().c_str(); 105 message->update_stream_packet().rect_data().data().data();
106
107 // Make sure there's enough data in |message|.
108 const int src_size =
109 message->update_stream_packet().rect_data().data().length();
110 if (src_size != src_stride * rect_height_)
111 return false;
112
113 // Make sure there's enough space for us to write to.
114 if (frame_->height() < static_cast<size_t>(rect_height_) ||
115 frame_->stride(media::VideoFrame::kRGBPlane) < src_stride) {
116 return false;
117 }
118
106 int src_stride_dir = src_stride; 119 int src_stride_dir = src_stride;
107 if (reverse_rows_) { 120 if (reverse_rows_) {
108 // Copy rows from bottom to top to flip the image vertically. 121 // Copy rows from bottom to top to flip the image vertically.
109 src += (rect_height_ - 1) * src_stride; 122 src += (rect_height_ - 1) * src_stride;
110 // Change the direction of the stride to work bottom to top. 123 // Change the direction of the stride to work bottom to top.
111 src_stride_dir *= -1; 124 src_stride_dir *= -1;
112 } 125 }
113 const int dest_stride = frame_->stride(media::VideoFrame::kRGBPlane); 126 const int dest_stride = frame_->stride(media::VideoFrame::kRGBPlane);
114 uint8* dest = frame_->data(media::VideoFrame::kRGBPlane) + 127 uint8* dest = frame_->data(media::VideoFrame::kRGBPlane) +
115 dest_stride * rect_y_ + bytes_per_pixel_ * rect_x_; 128 dest_stride * rect_y_ + bytes_per_pixel_ * rect_x_;
(...skipping 10 matching lines...) Expand all
126 return true; 139 return true;
127 } 140 }
128 141
129 bool DecoderVerbatim::HandleEndRect(ChromotingHostMessage* message) { 142 bool DecoderVerbatim::HandleEndRect(ChromotingHostMessage* message) {
130 DCHECK_EQ(kWaitingForRectData, state_); 143 DCHECK_EQ(kWaitingForRectData, state_);
131 state_ = kWaitingForBeginRect; 144 state_ = kWaitingForBeginRect;
132 return true; 145 return true;
133 } 146 }
134 147
135 } // namespace remoting 148 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | remoting/base/decoder_verbatim_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698