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

Unified Diff: chrome/browser/media/webrtc/webrtc_browsertest_audio.cc

Issue 2404823002: Fix error handling in POSIX version of the base::File::GetLength. (Closed)
Patch Set: Fix error handling in POSIX version of the base::File::GetLength. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/files/memory_mapped_file_posix.cc ('k') | components/search_provider_logos/logo_cache_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/media/webrtc/webrtc_browsertest_audio.cc
diff --git a/chrome/browser/media/webrtc/webrtc_browsertest_audio.cc b/chrome/browser/media/webrtc/webrtc_browsertest_audio.cc
index 3ed59478f354a22a1b6f7fbaa3d52c21cf3b7a2d..041cfa585b3a385946f74861618a78244b65361e 100644
--- a/chrome/browser/media/webrtc/webrtc_browsertest_audio.cc
+++ b/chrome/browser/media/webrtc/webrtc_browsertest_audio.cc
@@ -27,10 +27,23 @@ std::unique_ptr<char[]> ReadWavFile(const base::FilePath& wav_filename,
return nullptr;
}
- size_t wav_file_length = wav_file.GetLength();
+ int64_t wav_file_length64 = wav_file.GetLength();
+ if (wav_file_length64 < 0) {
+ PLOG(ERROR) << "GetLength " << wav_file.GetPlatformFile();
+ return nullptr;
+ }
+ if (wav_file_length64 > std::numeric_limits<int>::max()) {
+ LOG(ERROR) << "File is too big: " << wav_filename.value();
+ return nullptr;
+ }
+ int wav_file_length = static_cast<int>(wav_file_length64);
+ if (!wav_file_length) {
+ LOG(ERROR) << "Input file is empty: " << wav_filename.value();
+ return nullptr;
+ }
std::unique_ptr<char[]> data(new char[wav_file_length]);
- size_t read_bytes = wav_file.Read(0, data.get(), wav_file_length);
+ int read_bytes = wav_file.Read(0, data.get(), wav_file_length);
if (read_bytes != wav_file_length) {
LOG(ERROR) << "Failed to read all bytes of " << wav_filename.value();
return nullptr;
« no previous file with comments | « base/files/memory_mapped_file_posix.cc ('k') | components/search_provider_logos/logo_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698