Chromium Code Reviews

Side by Side Diff: import/cross/archive_request.cc

Issue 118052: Fixes crash bug when gzipped tar file is corrupt. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/o3d/
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « no previous file | plugin/cross/async_loading.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 // @@REWRITE(insert c-copyright)
2 * Copyright 2009, Google Inc. 2 // @@REWRITE(delete-start)
3 * All rights reserved. 3 // Copyright 2009 Google Inc. All Rights Reserved.
4 * 4 // Author: crogers@google.com (Chris Rogers)
5 * Redistribution and use in source and binary forms, with or without 5 // @@REWRITE(delete-end)
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 6
33 // This file contains the definition of the ArchiveRequest class. 7 // This file contains the definition of the ArchiveRequest class.
34 8
35 #include "import/cross/precompile.h" 9 #include "import/cross/precompile.h"
36 10
37 #include "import/cross/archive_request.h" 11 #include "import/cross/archive_request.h"
38 12
39 #include "import/cross/targz_processor.h" 13 #include "import/cross/targz_processor.h"
40 #include "core/cross/pack.h" 14 #include "core/cross/pack.h"
41 15
(...skipping 57 matching lines...)
99 // Count the bytes as they stream in 73 // Count the bytes as they stream in
100 bytes_received_ += length; 74 bytes_received_ += length;
101 75
102 MemoryReadStream memory_stream(reinterpret_cast<uint8*>(data), length); 76 MemoryReadStream memory_stream(reinterpret_cast<uint8*>(data), length);
103 77
104 // Progressively decompress the bytes we've just been given 78 // Progressively decompress the bytes we've just been given
105 int result = 79 int result =
106 archive_processor_->ProcessCompressedBytes(&memory_stream, length); 80 archive_processor_->ProcessCompressedBytes(&memory_stream, length);
107 81
108 if (result != Z_OK && result != Z_STREAM_END) { 82 if (result != Z_OK && result != Z_STREAM_END) {
83 set_success(false);
84 set_error("Invalid gzipped tar file");
109 stream->Cancel(); // tell the browser to stop downloading 85 stream->Cancel(); // tell the browser to stop downloading
110 set_success(false); 86 // NOTE: Cancel will call NPP_Cancel which in turn will call
111 set_error("Invalid tar gz file"); 87 // ArchiveRequest::FinishedCallback so we don't do anything here since
112 if (onreadystatechange()) 88 // we may already have been deleted on return.
113 onreadystatechange()->Run(); // javascript callback with failure
114 } 89 }
115 90
116 return length; 91 return length;
117 } 92 }
118 93
119 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 94 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
120 // Loads the Archive file, calls the JS callback to notify success. 95 // Loads the Archive file, calls the JS callback to notify success.
121 void ArchiveRequest::FinishedCallback(DownloadStream *stream, 96 void ArchiveRequest::FinishedCallback(DownloadStream *stream,
122 bool success, 97 bool success,
123 const std::string &filename, 98 const std::string &filename,
124 const std::string &mime_type) { 99 const std::string &mime_type) {
125 set_ready_state(ArchiveRequest::STATE_LOADED); 100 set_ready_state(ArchiveRequest::STATE_LOADED);
126 101
127 // Since the standard codes only go far enough to tell us that the download 102 // Since the standard codes only go far enough to tell us that the download
128 // succeeded, we set the success [and implicitly the done] flags to give the 103 // succeeded, we set the success [and implicitly the done] flags to give the
129 // rest of the story. 104 // rest of the story.
130 set_success(success); 105 set_success(success);
131 if (!success) { 106 if (!success) {
132 // I have no idea if an error is already set here but one MUST be set 107 // I have no idea if an error is already set here but one MUST be set
133 // so let's check 108 // so let's check.
134 set_error("Could not download archive. It could be a permission-related " 109 if (error().empty()) {
135 "issue."); 110 set_error(String("Could not download archive: ") + uri());
111 }
136 } 112 }
137 if (onreadystatechange()) 113 if (onreadystatechange())
138 onreadystatechange()->Run(); 114 onreadystatechange()->Run();
139 } 115 }
140 116
141 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 117 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
142 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 118 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
143 // ArchiveCallbackClient methods 119 // ArchiveCallbackClient methods
144 120
145 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 121 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(...skipping 76 matching lines...)
222 198
223 // Remove the reference to the raw_data so we don't have undefined 199 // Remove the reference to the raw_data so we don't have undefined
224 // behavior after the callback. 200 // behavior after the callback.
225 raw_data_.Reset(); 201 raw_data_.Reset();
226 } 202 }
227 } 203 }
228 return true; 204 return true;
229 } 205 }
230 206
231 } // namespace o3d 207 } // namespace o3d
OLDNEW
« no previous file with comments | « no previous file | plugin/cross/async_loading.cc » ('j') | no next file with comments »

Powered by Google App Engine