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

Side by Side Diff: courgette/third_party/bsdiff_apply.cc

Issue 6716006: Identifying call sites that need to handle out of memory situations in Courgette. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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
« no previous file with comments | « courgette/streams_unittest.cc ('k') | courgette/third_party/bsdiff_create.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 /*- 1 /*-
2 * Copyright 2003,2004 Colin Percival 2 * Copyright 2003,2004 Colin Percival
3 * All rights reserved 3 * All rights reserved
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted providing that the following conditions 6 * modification, are permitted providing that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 SourceStream* diff_skips = patch_streams.stream(3); 70 SourceStream* diff_skips = patch_streams.stream(3);
71 SourceStream* diff_bytes = patch_streams.stream(4); 71 SourceStream* diff_bytes = patch_streams.stream(4);
72 SourceStream* extra_bytes = patch_streams.stream(5); 72 SourceStream* extra_bytes = patch_streams.stream(5);
73 73
74 const uint8* extra_start = extra_bytes->Buffer(); 74 const uint8* extra_start = extra_bytes->Buffer();
75 const uint8* extra_end = extra_start + extra_bytes->Remaining(); 75 const uint8* extra_end = extra_start + extra_bytes->Remaining();
76 const uint8* extra_position = extra_start; 76 const uint8* extra_position = extra_start;
77 77
78 const uint8* old_position = old_start; 78 const uint8* old_position = old_start;
79 79
80 new_stream->Reserve(header->dlen); 80 if (header->dlen && !new_stream->Reserve(header->dlen))
81 return MEM_ERROR;
81 82
82 uint32 pending_diff_zeros = 0; 83 uint32 pending_diff_zeros = 0;
83 if (!diff_skips->ReadVarint32(&pending_diff_zeros)) 84 if (!diff_skips->ReadVarint32(&pending_diff_zeros))
84 return UNEXPECTED_ERROR; 85 return UNEXPECTED_ERROR;
85 86
86 while (!control_stream_copy_counts->Empty()) { 87 while (!control_stream_copy_counts->Empty()) {
87 uint32 copy_count, extra_count; 88 uint32 copy_count, extra_count;
88 int32 seek_adjustment; 89 int32 seek_adjustment;
89 if (!control_stream_copy_counts->ReadVarint32(&copy_count)) 90 if (!control_stream_copy_counts->ReadVarint32(&copy_count))
90 return UNEXPECTED_ERROR; 91 return UNEXPECTED_ERROR;
(...skipping 16 matching lines...) Expand all
107 uint8 diff_byte = 0; 108 uint8 diff_byte = 0;
108 if (pending_diff_zeros) { 109 if (pending_diff_zeros) {
109 --pending_diff_zeros; 110 --pending_diff_zeros;
110 } else { 111 } else {
111 if (!diff_skips->ReadVarint32(&pending_diff_zeros)) 112 if (!diff_skips->ReadVarint32(&pending_diff_zeros))
112 return UNEXPECTED_ERROR; 113 return UNEXPECTED_ERROR;
113 if (!diff_bytes->Read(&diff_byte, 1)) 114 if (!diff_bytes->Read(&diff_byte, 1))
114 return UNEXPECTED_ERROR; 115 return UNEXPECTED_ERROR;
115 } 116 }
116 uint8 byte = old_position[i] + diff_byte; 117 uint8 byte = old_position[i] + diff_byte;
117 new_stream->Write(&byte, 1); 118 if (!new_stream->Write(&byte, 1))
119 return MEM_ERROR;
118 } 120 }
119 old_position += copy_count; 121 old_position += copy_count;
120 122
121 // Copy bytes from the extra block. 123 // Copy bytes from the extra block.
122 if (extra_count > static_cast<size_t>(extra_end - extra_position)) 124 if (extra_count > static_cast<size_t>(extra_end - extra_position))
123 return UNEXPECTED_ERROR; 125 return UNEXPECTED_ERROR;
124 126
125 new_stream->Write(extra_position, extra_count); 127 if (!new_stream->Write(extra_position, extra_count))
128 return MEM_ERROR;
129
126 extra_position += extra_count; 130 extra_position += extra_count;
127 131
128 // "seek" forwards (or backwards) in oldfile. 132 // "seek" forwards (or backwards) in oldfile.
129 if (old_position + seek_adjustment < old_start || 133 if (old_position + seek_adjustment < old_start ||
130 old_position + seek_adjustment > old_end) 134 old_position + seek_adjustment > old_end)
131 return UNEXPECTED_ERROR; 135 return UNEXPECTED_ERROR;
132 136
133 old_position += seek_adjustment; 137 old_position += seek_adjustment;
134 } 138 }
135 139
(...skipping 22 matching lines...) Expand all
158 162
159 if (CalculateCrc(old_start, old_size) != header.scrc32) 163 if (CalculateCrc(old_start, old_size) != header.scrc32)
160 return CRC_ERROR; 164 return CRC_ERROR;
161 165
162 MBS_ApplyPatch(&header, patch_stream, old_start, old_size, new_stream); 166 MBS_ApplyPatch(&header, patch_stream, old_start, old_size, new_stream);
163 167
164 return OK; 168 return OK;
165 } 169 }
166 170
167 } // namespace 171 } // namespace
OLDNEW
« no previous file with comments | « courgette/streams_unittest.cc ('k') | courgette/third_party/bsdiff_create.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698