From: Michael Vogt Date: Mon, 6 Oct 2014 15:42:39 +0000 (+0200) Subject: make http size check work X-Git-Tag: 1.1.exp4~5^2~9 X-Git-Url: https://git.saurik.com/apt.git/commitdiff_plain/a2d40703e4a5590a689ace4466f92e590434944d make http size check work --- a2d40703e4a5590a689ace4466f92e590434944d diff --cc methods/http.cc index 916fa464f,f2a4a4db6..b076e59cc --- a/methods/http.cc +++ b/methods/http.cc @@@ -653,10 -651,6 +655,12 @@@ bool HttpServerState::Go(bool ToFile, F return _error->Errno("write",_("Error writing to output file")); } - if (ExpectedSize > 0 && In.TotalWriten > ExpectedSize) ++ if (ExpectedSize > 0 && File && File->Tell() > ExpectedSize) ++ { + return _error->Error("Writing more data than expected (%llu > %llu)", - In.TotalWriten, ExpectedSize); ++ File->Tell(), ExpectedSize); ++ } + // Handle commands from APT if (FD_ISSET(STDIN_FILENO,&rfds)) { diff --cc methods/https.h index 2335559fb,45d1f7f63..0387cb9b5 --- a/methods/https.h +++ b/methods/https.h @@@ -70,10 -69,9 +70,9 @@@ class HttpsMethod : public pkgAcqMetho public: FileFd *File; - - HttpsMethod() : pkgAcqMethod("1.2",Pipeline | SendConfig), Server(NULL), File(NULL) + - HttpsMethod() : pkgAcqMethod("1.2",Pipeline | SendConfig), TotalWritten(0), File(NULL) ++ HttpsMethod() : pkgAcqMethod("1.2",Pipeline | SendConfig), Server(NULL), TotalWritten(0), File(NULL) { - File = 0; curl = curl_easy_init(); }; diff --cc methods/server.cc index 1b6511c59,4a961f454..223737901 --- a/methods/server.cc +++ b/methods/server.cc @@@ -609,7 -605,7 +610,10 @@@ int ServerMethod::Loop( QueueBack = Queue; } else ++ { ++ Server->Close(); Fail(true); ++ } } break; } diff --cc test/integration/test-apt-update-expected-size index 000000000,000000000..72812336d new file mode 100755 --- /dev/null +++ b/test/integration/test-apt-update-expected-size @@@ -1,0 -1,0 +1,27 @@@ ++#!/bin/sh ++set -e ++ ++TESTDIR=$(readlink -f $(dirname $0)) ++. $TESTDIR/framework ++ ++setupenvironment ++configarchitecture "i386" ++ ++insertpackage 'unstable' 'apt' 'all' '1.0' ++ ++setupaptarchive --no-update ++changetowebserver ++ ++# normal update works fine ++testsuccess aptget update ++ ++# append junk at the end of the Packages.gz/Packages ++SIZE="$(stat --printf=%s aptarchive/dists/unstable/main/binary-i386/Packages)" ++echo "1234567890" >> aptarchive/dists/unstable/main/binary-i386/Packages.gz ++echo "1234567890" >> aptarchive/dists/unstable/main/binary-i386/Packages ++NEW_SIZE="$(stat --printf=%s aptarchive/dists/unstable/main/binary-i386/Packages)" ++rm -f rootdir/var/lib/apt/lists/localhost* ++testequal "W: Failed to fetch http://localhost:8080/dists/unstable/main/binary-i386/Packages Writing more data than expected ($NEW_SIZE > $SIZE) [IP: ::1 8080] ++ ++E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq ++