]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Handle more partial responses (#791) 807/head
authorAlex Rousskov <rousskov@measurement-factory.com>
Fri, 2 Apr 2021 07:46:20 +0000 (07:46 +0000)
committerAmos Jeffries <yadij@users.noreply.github.com>
Tue, 6 Apr 2021 02:37:01 +0000 (14:37 +1200)
src/HttpHdrContRange.cc
src/HttpHeaderRange.h
src/clients/Client.cc
src/http/Stream.cc

index b0e011fec4b844c8c655328f128d6daab929ef8e..be07b4a3d7fbdbeb139dc9db299bb9389c5830be 100644 (file)
@@ -161,9 +161,13 @@ httpHdrContRangeParseInit(HttpHdrContRange * range, const char *str)
 
     ++p;
 
-    if (*p == '*')
+    if (*p == '*') {
+        if (!known_spec(range->spec.offset)) {
+            debugs(68, 2, "invalid (*/*) content-range-spec near: '" << str << "'");
+            return 0;
+        }
         range->elength = range_spec_unknown;
-    else if (!httpHeaderParseOffset(p, &range->elength))
+    else if (!httpHeaderParseOffset(p, &range->elength))
         return 0;
     else if (range->elength <= 0) {
         /* Additional paranoidal check for BUG2155 - entity-length MUST be > 0 */
@@ -174,6 +178,12 @@ httpHdrContRangeParseInit(HttpHdrContRange * range, const char *str)
         return 0;
     }
 
+    // reject unsatisfied-range and such; we only use well-defined ranges today
+    if (!known_spec(range->spec.offset) || !known_spec(range->spec.length)) {
+        debugs(68, 2, "unwanted content-range-spec near: '" << str << "'");
+        return 0;
+    }
+
     debugs(68, 8, "parsed content-range field: " <<
            (long int) range->spec.offset << "-" <<
            (long int) range->spec.offset + range->spec.length - 1 << " / " <<
index fb2956365e3ee09e53070659d9407f3da28d8d2f..21fc7f6b2875532d63986150355c78f96509fd7c 100644 (file)
 class HttpReply;
 class Packable;
 
-/* http byte-range-spec */
-
+// TODO: Refactor to disambiguate and provide message-specific APIs.
+/// either byte-range-spec (in a request Range header)
+/// or suffix-byte-range-spec (in a request Range header)
+/// or byte-range part of byte-range-resp (in a response Content-Range header)
+/// or "*" part of unsatisfied-range (in a response Content-Range header)
 class HttpHdrRangeSpec
 {
     MEMPROXY_CLASS(HttpHdrRangeSpec);
index b6ce419a6bbc047a2be00d033a877c8559ae4ee1..f5defbb63e630afa4054aba17694b107c89c01ca 100644 (file)
@@ -533,8 +533,11 @@ Client::haveParsedReplyHeaders()
     maybePurgeOthers();
 
     // adaptation may overwrite old offset computed using the virgin response
-    const bool partial = theFinalReply->contentRange();
-    currentOffset = partial ? theFinalReply->contentRange()->spec.offset : 0;
+    currentOffset = 0;
+    if (const auto cr = theFinalReply->contentRange()) {
+        if (cr->spec.offset != HttpHdrRangeSpec::UnknownPosition)
+            currentOffset = cr->spec.offset;
+    }
 }
 
 /// whether to prevent caching of an otherwise cachable response
index 338503b4a417173e65070c6fa466018aa2766752..cea509a5502699485f0c69b154b36a23d31880f2 100644 (file)
@@ -163,12 +163,13 @@ Http::Stream::getNextRangeOffset() const
             return start;
         }
 
-    } else if (reply && reply->contentRange()) {
+    } else if (const auto cr = reply ? reply->contentRange() : nullptr) {
         /* request does not have ranges, but reply does */
         /** \todo FIXME: should use range_iter_pos on reply, as soon as reply->content_range
          *        becomes HttpHdrRange rather than HttpHdrRangeSpec.
          */
-        return http->out.offset + reply->contentRange()->spec.offset;
+        if (cr->spec.offset != HttpHdrRangeSpec::UnknownPosition)
+            return http->out.offset + cr->spec.offset;
     }
 
     return http->out.offset;
@@ -232,6 +233,10 @@ Http::Stream::socketState()
 
             // did we get at least what we expected, based on range specs?
 
+            // this Content-Range does not tell us how many bytes to expect
+            if (bytesExpected == HttpHdrRangeSpec::UnknownPosition)
+                return STREAM_NONE;
+
             if (bytesSent == bytesExpected) // got everything
                 return STREAM_COMPLETE;