master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include "unitcheck.h"
25#include "urldata.h"
26#include "curl_range.h"
28/* Only include this test if one or more of FTP, FILE are enabled. */
29#if !defined(CURL_DISABLE_FTP) || !defined(CURL_DISABLE_FILE)
31static CURLcode t1694_setup(struct Curl_easy **easy)
32{
33 CURLcode result;
35 result = curl_global_init(CURL_GLOBAL_ALL);
36 if(result)
37 return result; /* init failed us */
39 *easy = curl_easy_init();
40 if(!*easy) {
41 curl_global_cleanup(); /* roll back the half we did succeed at */
42 return CURLE_OUT_OF_MEMORY;
43 }
45 return CURLE_OK;
46}
48static void t1694_stop(struct Curl_easy *easy)
49{
50 curl_easy_cleanup(easy);
51 curl_global_cleanup();
52}
54static CURLcode test_unit1694(const char *arg)
55{
56 struct Curl_easy *easy;
58 UNITTEST_BEGIN(t1694_setup(&easy))
60 struct testcase {
61 /* Input values */
62 bool use_range; /* value for state.use_range */
63 const char *range; /* value for state.range, or NULL */
64 /* Output values */
65 CURLcode result; /* expected return from Curl_range() */
66 curl_off_t resume_from; /* expected state.resume_from after the call */
67 curl_off_t maxdownload; /* expected req.maxdownload after the call */
68 };
70 static const struct testcase tests[] = {
72 /* Make sure Curl_range doesn't do anything unless the range
73 * request data is initialized.
74 *
75 * The use_range and range variables are ANDead together
76 * at the top of this function. So for 3 out of 4 scenarios
77 * where either of these could be uninitialized, we skip most
78 * of the Curl_range code. Still returns "CURLE_OK" and
79 * maxdownload set to -1 or "unlimited". */
81 { FALSE, NULL, CURLE_OK, -7, -1 },
82 { FALSE, "0-100", CURLE_OK, -7, -1 },
83 { TRUE, NULL, CURLE_OK, -7, -1 },
85 /* */
86 /* Let's feed Curl_range some invalid ranges */
87 /* */
89 /* Text instead of a numerical range */
90 { TRUE, "NotANumber", CURLE_RANGE_ERROR, -7, -8 },
91 /* Hexadecimal not supported */
92 { TRUE, "0XBEEF-0XDEAD", CURLE_RANGE_ERROR, -7, -8 },
93 { TRUE, "0xbeef-0xdead", CURLE_RANGE_ERROR, -7, -8 },
94 /* Passing in "-0" should fail */
95 { TRUE, "-0", CURLE_RANGE_ERROR, -7, -8 },
96 /* Passing in a "from" greater than the "to" should fail */
97 { TRUE, "130-50", CURLE_RANGE_ERROR, -7, -8 },
98 /* Passing in a range that is greater than CURL_OFF_T_MAX
99 * should fail */
100 { TRUE, "0-9223372036854775807", CURLE_RANGE_ERROR, -7, -8 },
101 /* Use a character from the zero area of the
102 * curlx_hexasciitable */
103 { TRUE, ":100-100", CURLE_RANGE_ERROR, -7, -8 },
104 { TRUE, "100:-100", CURLE_RANGE_ERROR, -7, -8 },
105 { TRUE, "_100-100", CURLE_RANGE_ERROR, -7, -8 },
106 { TRUE, "100_-100", CURLE_RANGE_ERROR, -7, -8 },
108 /* */
109 /* Single number tests */
110 /* */
112 { TRUE, "125", CURLE_RANGE_ERROR, -7, -8 },
113 { TRUE, " 126", CURLE_RANGE_ERROR, -7, -8 },
114 { TRUE, " 127", CURLE_RANGE_ERROR, -7, -8 },
115 { TRUE, "128 ", CURLE_RANGE_ERROR, -7, -8 },
116 { TRUE, "129 ", CURLE_RANGE_ERROR, -7, -8 },
117 { TRUE, "\t131", CURLE_RANGE_ERROR, -7, -8 },
118 { TRUE, "\t\t132", CURLE_RANGE_ERROR, -7, -8 },
119 { TRUE, "133\t", CURLE_RANGE_ERROR, -7, -8 },
120 { TRUE, "134\t\t", CURLE_RANGE_ERROR, -7, -8 },
122 /* */
123 /* No second number tests */
124 /* */
126 /* Returns OK and sets resume_from, maxdownload NOT set.
127 * Comments mention " to end of file", so shouldn't
128 * maxdownload be set to -1? */
129 { TRUE, "101-", CURLE_OK, 101, -8 },
130 { TRUE, "102- ", CURLE_OK, 102, -8 },
131 { TRUE, "103- ", CURLE_OK, 103, -8 },
132 { TRUE, "102-\t", CURLE_OK, 102, -8 },
133 { TRUE, "103-\t\t", CURLE_OK, 103, -8 },
134 /* Returns Error */
135 { TRUE, " 113-", CURLE_RANGE_ERROR, -7, -8 },
136 { TRUE, " 135-", CURLE_RANGE_ERROR, -7, -8 },
137 { TRUE, "114 -", CURLE_RANGE_ERROR, -7, -8 },
138 { TRUE, "136 -", CURLE_RANGE_ERROR, -7, -8 },
139 { TRUE, "\t113-", CURLE_RANGE_ERROR, -7, -8 },
140 { TRUE, "\t\t135-", CURLE_RANGE_ERROR, -7, -8 },
141 { TRUE, "114\t-", CURLE_RANGE_ERROR, -7, -8 },
142 { TRUE, "136\t\t-", CURLE_RANGE_ERROR, -7, -8 },
144 /* */
145 /* No first number tests */
146 /* */
148 /* Typical success path */
149 { TRUE, "-104", CURLE_OK, -104, 104 },
150 { TRUE, "-105 ", CURLE_OK, -105, 105 },
151 { TRUE, "-106 ", CURLE_OK, -106, 106 },
152 { TRUE, "-142\t", CURLE_OK, -142, 142 },
153 { TRUE, "-143\t\t", CURLE_OK, -143, 143 },
154 /* Sees that there is no 1st number, finds the dash and
155 * skips it, sees no 2nd number due to the whitespace,
156 * resume_from set to 0 via call to str_num_base, no writes to
157 * maxdownload. */
158 { TRUE, "- 121", CURLE_OK, 0, -8 },
159 { TRUE, "- 122", CURLE_OK, 0, -8 },
160 { TRUE, "-\t140", CURLE_OK, 0, -8 },
161 { TRUE, "-\t\t141", CURLE_OK, 0, -8 },
162 /* Returns Error */
163 { TRUE, " -115", CURLE_RANGE_ERROR, -7, -8 },
164 { TRUE, " -137", CURLE_RANGE_ERROR, -7, -8 },
165 { TRUE, "\t-138", CURLE_RANGE_ERROR, -7, -8 },
166 { TRUE, "\t\t-139", CURLE_RANGE_ERROR, -7, -8 },
168 /* */
169 /* Two number tests, single byte range */
170 /* */
172 /* Typical success path */
173 { TRUE, "100-100", CURLE_OK, 100, 1 },
174 { TRUE, "101-101 ", CURLE_OK, 101, 1 },
175 { TRUE, "101-101\t", CURLE_OK, 101, 1 },
176 /* Parser can't get past the whitespace after the dash,
177 * takes the no second number path in the code. */
178 { TRUE, "102- 102", CURLE_OK, 102, -8 },
179 { TRUE, "103- 103 ", CURLE_OK, 103, -8 },
180 { TRUE, "102-\t102", CURLE_OK, 102, -8 },
181 { TRUE, "103-\t103\t", CURLE_OK, 103, -8 },
182 /* Returns Error */
183 { TRUE, "105 -105 ", CURLE_RANGE_ERROR, -7, -8 },
184 { TRUE, "104 -104", CURLE_RANGE_ERROR, -7, -8 },
185 { TRUE, "106 - 106", CURLE_RANGE_ERROR, -7, -8 },
186 { TRUE, "107 - 107 ", CURLE_RANGE_ERROR, -7, -8 },
187 { TRUE, " 200-200", CURLE_RANGE_ERROR, -7, -8 },
188 { TRUE, " 201-201 ", CURLE_RANGE_ERROR, -7, -8 },
189 { TRUE, " 202- 202", CURLE_RANGE_ERROR, -7, -8 },
190 { TRUE, " 203- 203 ", CURLE_RANGE_ERROR, -7, -8 },
191 { TRUE, " 205 -205 ", CURLE_RANGE_ERROR, -7, -8 },
192 { TRUE, " 204 -204", CURLE_RANGE_ERROR, -7, -8 },
193 { TRUE, " 206 - 206", CURLE_RANGE_ERROR, -7, -8 },
194 { TRUE, " 207 - 207 ", CURLE_RANGE_ERROR, -7, -8 },
195 { TRUE, "105\t-105\t", CURLE_RANGE_ERROR, -7, -8 },
196 { TRUE, "104\t-104", CURLE_RANGE_ERROR, -7, -8 },
197 { TRUE, "106\t-\t106", CURLE_RANGE_ERROR, -7, -8 },
198 { TRUE, "107\t-\t107\t", CURLE_RANGE_ERROR, -7, -8 },
199 { TRUE, "\t200-200", CURLE_RANGE_ERROR, -7, -8 },
200 { TRUE, "\t201-201\t", CURLE_RANGE_ERROR, -7, -8 },
201 { TRUE, "\t202-\t202", CURLE_RANGE_ERROR, -7, -8 },
202 { TRUE, "\t203-\t203\t", CURLE_RANGE_ERROR, -7, -8 },
203 { TRUE, "\t205\t-205\t", CURLE_RANGE_ERROR, -7, -8 },
204 { TRUE, "\t204\t-204", CURLE_RANGE_ERROR, -7, -8 },
205 { TRUE, "\t206\t-\t206", CURLE_RANGE_ERROR, -7, -8 },
206 { TRUE, "\t207\t-\t207 ", CURLE_RANGE_ERROR, -7, -8 },
208 /* */
209 /* Two number tests, range of bytes */
210 /* */
212 /* Typical success path */
213 { TRUE, "300-500", CURLE_OK, 300, 201 },
214 { TRUE, "301-501 ", CURLE_OK, 301, 201 },
215 { TRUE, "301-501\t", CURLE_OK, 301, 201 },
216 /* Parser can't get past the whitespace after the dash,
217 * takes the no second number path in the code. */
218 { TRUE, "302- 502", CURLE_OK, 302, -8 },
219 { TRUE, "303- 503 ", CURLE_OK, 303, -8 },
220 { TRUE, "302-\t502", CURLE_OK, 302, -8 },
221 { TRUE, "303-\t503\t", CURLE_OK, 303, -8 },
222 /* Returns Error */
223 { TRUE, "305 -505 ", CURLE_RANGE_ERROR, -7, -8 },
224 { TRUE, "304 -504", CURLE_RANGE_ERROR, -7, -8 },
225 { TRUE, "306 - 506", CURLE_RANGE_ERROR, -7, -8 },
226 { TRUE, "307 - 507 ", CURLE_RANGE_ERROR, -7, -8 },
227 { TRUE, " 400-600", CURLE_RANGE_ERROR, -7, -8 },
228 { TRUE, " 401-601 ", CURLE_RANGE_ERROR, -7, -8 },
229 { TRUE, " 402- 602", CURLE_RANGE_ERROR, -7, -8 },
230 { TRUE, " 403- 603 ", CURLE_RANGE_ERROR, -7, -8 },
231 { TRUE, " 405 -605 ", CURLE_RANGE_ERROR, -7, -8 },
232 { TRUE, " 404 -604", CURLE_RANGE_ERROR, -7, -8 },
233 { TRUE, " 406 - 606", CURLE_RANGE_ERROR, -7, -8 },
234 { TRUE, " 407 - 607 ", CURLE_RANGE_ERROR, -7, -8 },
235 { TRUE, "305\t-505\t", CURLE_RANGE_ERROR, -7, -8 },
236 { TRUE, "304\t-504", CURLE_RANGE_ERROR, -7, -8 },
237 { TRUE, "306\t-\t506", CURLE_RANGE_ERROR, -7, -8 },
238 { TRUE, "307\t-\t507\t", CURLE_RANGE_ERROR, -7, -8 },
239 { TRUE, "\t400-600", CURLE_RANGE_ERROR, -7, -8 },
240 { TRUE, "\t401-601\t", CURLE_RANGE_ERROR, -7, -8 },
241 { TRUE, "\t402-\t602", CURLE_RANGE_ERROR, -7, -8 },
242 { TRUE, "\t403-\t603\t", CURLE_RANGE_ERROR, -7, -8 },
243 { TRUE, "\t405\t-605\t", CURLE_RANGE_ERROR, -7, -8 },
244 { TRUE, "\t404\t-604", CURLE_RANGE_ERROR, -7, -8 },
245 { TRUE, "\t406\t-\t606", CURLE_RANGE_ERROR, -7, -8 },
246 { TRUE, "\t407\t-\t607 ", CURLE_RANGE_ERROR, -7, -8 },
248 /* Largest supported range, and ends at the largest supported
249 * number: (2^63 - 1) */
250 { TRUE, "1-9223372036854775807", CURLE_OK, 1, 9223372036854775807},
252 /* */
253 /* Mix of positive and negative */
254 /* */
256 /* These schenarios are returning OK, but have the same
257 * logic challenges as above, due to the extra '-', ' ',
258 * and '+'. */
259 { TRUE, "-108 - 208", CURLE_OK, -108, 108 },
260 { TRUE, "-109 - +209", CURLE_OK, -109, 109 },
261 { TRUE, "-110 - -210", CURLE_OK, -110, 110 },
262 { TRUE, "-108-208", CURLE_OK, -108, 108 },
263 { TRUE, "-109-+209", CURLE_OK, -109, 109 },
264 { TRUE, "-110--210", CURLE_OK, -110, 110 },
265 { TRUE, "101-+201", CURLE_OK, 101, -8 },
266 { TRUE, "102--202", CURLE_OK, 102, -8 },
267 { TRUE, "103-+203", CURLE_OK, 103, -8 },
268 /* Returns Error */
269 { TRUE, "101 - +201", CURLE_RANGE_ERROR, -7, -8 },
270 { TRUE, "102 - -202", CURLE_RANGE_ERROR, -7, -8 },
271 { TRUE, "103 - +203", CURLE_RANGE_ERROR, -7, -8 },
272 { TRUE, "+104 - 204", CURLE_RANGE_ERROR, -7, -8 },
273 { TRUE, "+105 - +205", CURLE_RANGE_ERROR, -7, -8 },
274 { TRUE, "+106 - -206", CURLE_RANGE_ERROR, -7, -8 },
275 { TRUE, "+104-204", CURLE_RANGE_ERROR, -7, -8 },
276 { TRUE, "+105-+205", CURLE_RANGE_ERROR, -7, -8 },
277 { TRUE, "+106--206", CURLE_RANGE_ERROR, -7, -8 },
279 /* */
280 /* Other success paths */
281 /* */
283 /* Curl ignores leading zeros */
284 { TRUE, "0008-0012", CURLE_OK, 8, 5 },
285 /* A single 0 at the beginning of a value is treated as an
286 * octal value in C source code. So going from an octal byte
287 * 7 to an octal byte 10 would be 2 bytes. Curl treats its
288 * inputs as base 10 strings, so Curl would interpret this
289 * as byte 7 to byte 10 and a 4 byte spread. */
290 { TRUE, "07-010", CURLE_OK, 7, 4 }
292 };
294 size_t i;
296 for(i = 0; i < CURL_ARRAYSIZE(tests); i++) {
297 CURLcode result;
298 const char *range_str; /* printable version of the range for messages */
300 /* Initialize the outputs in case any subsequent test paths
301 * skip any writes to these values */
302 easy->result = CURLE_UNSUPPORTED_PROTOCOL;
303 easy->state.resume_from = -7;
304 easy->req.maxdownload = -8;
306 /* Set the input use_range flag according to the test case */
307 easy->state.use_range = tests[i].use_range;
309 /* Setup the input range, including a printable version */
310 if(tests[i].range) {
311 range_str = tests[i].range;
312 easy->state.range = curlx_strdup(tests[i].range);
313 if(!easy->state.range) {
314 curl_mprintf("curlx_strdup failed for test case [%zu]\n", i);
315 unittest_abort("out of memory");
316 }
317 }
318 else {
319 range_str = "(null)";
320 easy->state.range = NULL;
321 }
323 result = Curl_range(easy); /* Exercise the code under test */
325 /* Check the result code */
326 if(result != tests[i].result) {
327 curl_mprintf("Curl_range(\"%s\") returned %d, expected %d [%zu]\n",
328 range_str, (int)result, (int)tests[i].result, i);
329 fail("unexpected result code");
330 }
332 /* Check the resume_from value */
333 if(easy->state.resume_from != tests[i].resume_from) {
334 curl_mprintf("Curl_range(\"%s\") set resume_from to %" FMT_OFF_T
335 ", expected %" FMT_OFF_T " [%zu]\n",
336 range_str, easy->state.resume_from,
337 tests[i].resume_from, i);
338 fail("resume_from mismatch");
339 }
341 /* Check the maxdownload value */
342 if(easy->req.maxdownload != tests[i].maxdownload) {
343 curl_mprintf("Curl_range(\"%s\") set maxdownload to %" FMT_OFF_T
344 ", expected %" FMT_OFF_T " [%zu]\n",
345 range_str, easy->req.maxdownload,
346 tests[i].maxdownload, i);
347 fail("maxdownload mismatch");
348 }
350 /* Clean up after ourselves */
351 if(tests[i].range)
352 curlx_free(easy->state.range);
353 }
355 UNITTEST_END(t1694_stop(easy))
356}
358#else
360static CURLcode test_unit1694(const char *arg)
361{
362 UNITTEST_BEGIN_SIMPLE
363 puts("not tested since FTP and FILE are disabled");
364 UNITTEST_END_SIMPLE
365}
367#endif /* !CURL_DISABLE_FTP || !CURL_DISABLE_FILE */
Diagnostics4 git calls · 39 ms
CallStatusSizeTime039 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=2 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit5 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=31 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=5 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2003.8 KiB · hit32 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=3888 git.response.cache=HIT git.response.duration_ms=32 git.fetch.wants=03ea75615598a686ca0ace453c90f9179dc43767 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=3888 git.pkt.payload.max=3867 git.sideband.band1.bytes=3866 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e2e972dcce4bc2
- Request
- 4f2855fe…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format