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

Side by Side Diff: net/ftp/ftp_directory_listing_parser_vms_unittest.cc

Issue 2611933003: Avoid signed integer overflow when calculating filesizes for VMS's ftp listings. (Closed)
Patch Set: Add another test Created 3 years, 11 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 | « net/ftp/ftp_directory_listing_parser_vms.cc ('k') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "net/ftp/ftp_directory_listing_parser_unittest.h" 5 #include "net/ftp/ftp_directory_listing_parser_unittest.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 std::vector<FtpDirectoryListingEntry> entries; 70 std::vector<FtpDirectoryListingEntry> entries;
71 EXPECT_TRUE(ParseFtpDirectoryListingVms(lines, 71 EXPECT_TRUE(ParseFtpDirectoryListingVms(lines,
72 &entries)); 72 &entries));
73 VerifySingleLineTestCase(good_cases[i], entries); 73 VerifySingleLineTestCase(good_cases[i], entries);
74 } 74 }
75 } 75 }
76 76
77 TEST_F(FtpDirectoryListingParserVmsTest, Bad) { 77 TEST_F(FtpDirectoryListingParserVmsTest, Bad) {
78 const char* const bad_cases[] = { 78 const char* const bad_cases[] = {
79 "garbage", 79 "garbage",
80 80
81 // Missing file version number. 81 // Missing file version number.
82 "README.TXT 2 18-APR-2000 10:40:39", 82 "README.TXT 2 18-APR-2000 10:40:39",
83 83
84 // Missing extension. 84 // Missing extension.
85 "README;1 2 18-APR-2000 10:40:39", 85 "README;1 2 18-APR-2000 10:40:39",
86 86
87 // Malformed file size. 87 // Malformed file size.
88 "README.TXT;1 garbage 18-APR-2000 10:40:39", 88 "README.TXT;1 garbage 18-APR-2000 10:40:39",
89 "README.TXT;1 -2 18-APR-2000 10:40:39", 89 "README.TXT;1 -2 18-APR-2000 10:40:39",
90 90
91 // Malformed date. 91 // Malformed date.
92 "README.TXT;1 2 APR-2000 10:40:39", 92 "README.TXT;1 2 APR-2000 10:40:39",
93 "README.TXT;1 2 -18-APR-2000 10:40:39", 93 "README.TXT;1 2 -18-APR-2000 10:40:39", "README.TXT;1 2 18-APR 10:40:39",
94 "README.TXT;1 2 18-APR 10:40:39", 94 "README.TXT;1 2 18-APR-2000 10", "README.TXT;1 2 18-APR-2000 10:40.25",
95 "README.TXT;1 2 18-APR-2000 10", 95 "README.TXT;1 2 18-APR-2000 10:40.25.25",
96 "README.TXT;1 2 18-APR-2000 10:40.25",
97 "README.TXT;1 2 18-APR-2000 10:40.25.25",
98 96
99 // Malformed security information. 97 // Malformed security information.
100 "X.TXT;2 1 12-MAR-2005 08:44:57 (RWED,RWED,RE,RE)", 98 "X.TXT;2 1 12-MAR-2005 08:44:57 (RWED,RWED,RE,RE)",
101 "X.TXT;2 1 12-MAR-2005 08:44:57 [SYSTEM]", 99 "X.TXT;2 1 12-MAR-2005 08:44:57 [SYSTEM]",
102 "X.TXT;2 1 12-MAR-2005 08:44:57 (SYSTEM) (RWED,RWED,RE,RE)", 100 "X.TXT;2 1 12-MAR-2005 08:44:57 (SYSTEM) (RWED,RWED,RE,RE)",
103 "X.TXT;2 1 12-MAR-2005 08:44:57 [SYSTEM] [RWED,RWED,RE,RE]", 101 "X.TXT;2 1 12-MAR-2005 08:44:57 [SYSTEM] [RWED,RWED,RE,RE]",
104 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED)", 102 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED)",
105 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,RE,RE,RE)", 103 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,RE,RE,RE)",
106 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWEDRWED,RE,RE)", 104 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWEDRWED,RE,RE)",
107 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,DEWR,RE,RE)", 105 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,DEWR,RE,RE)",
108 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,Q,RE)", 106 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RWED,Q,RE)",
109 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RRWWEEDD,RE,RE)", 107 "X.TXT;2 1 12-MAR-2005 08:44:57 [X] (RWED,RRWWEEDD,RE,RE)",
108
109 // Block size is too large, leading to overflow when calculating
110 // file size.
111 "README.TXT;1 9223372036854775807 18-APR-2000 10:40:39.90",
112 "README.TXT;1 9223372036854775807/9223372036854775807 18-APR-2000 "
113 "10:40:39.90",
114
115 // Block size is too large (bigger than int64 max)
116 "README.TXT;1 19223372036854775807 18-APR-2000 10:40:39.90",
117 "README.TXT;1 19223372036854775807/19223372036854775807 18-APR-2000 "
mmenke 2017/01/04 19:07:24 Also a test where block site is not too large (Nor
eroman 2017/01/04 20:16:58 Done.
118 "10:40:39.90",
110 }; 119 };
111 for (size_t i = 0; i < arraysize(bad_cases); i++) { 120 for (size_t i = 0; i < arraysize(bad_cases); i++) {
112 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, bad_cases[i])); 121 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, bad_cases[i]));
113 122
114 std::vector<base::string16> lines(GetSingleLineTestCase(bad_cases[i])); 123 std::vector<base::string16> lines(GetSingleLineTestCase(bad_cases[i]));
115 124
116 // The parser requires a directory header before accepting regular input. 125 // The parser requires a directory header before accepting regular input.
117 lines.insert(lines.begin(), 126 lines.insert(lines.begin(),
118 ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]")); 127 ASCIIToUTF16("Directory ANONYMOUS_ROOT:[000000]"));
119 128
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 195
187 lines.push_back(ASCIIToUTF16(" ")); 196 lines.push_back(ASCIIToUTF16(" "));
188 197
189 std::vector<FtpDirectoryListingEntry> entries; 198 std::vector<FtpDirectoryListingEntry> entries;
190 EXPECT_FALSE(ParseFtpDirectoryListingVms(lines, &entries)); 199 EXPECT_FALSE(ParseFtpDirectoryListingVms(lines, &entries));
191 } 200 }
192 201
193 } // namespace 202 } // namespace
194 203
195 } // namespace net 204 } // namespace net
OLDNEW
« no previous file with comments | « net/ftp/ftp_directory_listing_parser_vms.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698