From a2406cda4dd0aca523183ed6a8b651f06e0e63f9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 4 Jun 2021 16:15:45 +0200 Subject: No URL decode and quoting support for Files in Sources The code exists since ever, but no other client supports this and the specification like debian-policy isn't asking for this either. What it does do is breaking than all others continue working through: If the filename includes in fact URI encoded bits (hopefully no quotes) which is rather unlikely, but none the less possible. --- apt-pkg/deb/debsrcrecords.cc | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debsrcrecords.cc b/apt-pkg/deb/debsrcrecords.cc index 89f3f1667..1fd0fdc12 100644 --- a/apt-pkg/deb/debsrcrecords.cc +++ b/apt-pkg/deb/debsrcrecords.cc @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -170,6 +171,7 @@ bool debSrcRecordParser::Files(std::vector &List) std::vector const compExts = APT::Configuration::getCompressorExtensions(); + auto const &posix = std::locale::classic(); for (char const * const * type = HashString::SupportedHashes(); *type != NULL; ++type) { // derive field from checksum type @@ -182,27 +184,23 @@ bool debSrcRecordParser::Files(std::vector &List) string const Files = Sect.FindS(checksumField.c_str()); if (Files.empty() == true) continue; + std::istringstream ss(Files); + ss.imbue(posix); - // Iterate over the entire list grabbing each triplet - const char *C = Files.c_str(); - while (*C != 0) + while (ss.good()) { - string hash, size, path; - - // Parse each of the elements - if (ParseQuoteWord(C, hash) == false || - ParseQuoteWord(C, size) == false || - ParseQuoteWord(C, path) == false) - return _error->Error("Error parsing file record in %s of source package %s", checksumField.c_str(), Package().c_str()); - + std::string hash, path; + unsigned long long size; if (iIndex == nullptr && checksumField == "Files") { - // the Files field has a different format than the rest in deb-changes files std::string ignore; - if (ParseQuoteWord(C, ignore) == false || - ParseQuoteWord(C, path) == false) - return _error->Error("Error parsing file record in %s of source package %s", checksumField.c_str(), Package().c_str()); + ss >> hash >> size >> ignore >> ignore >> path; } + else + ss >> hash >> size >> path; + + if (ss.fail() || hash.empty() || path.empty()) + return _error->Error("Error parsing file record in %s of source package %s", checksumField.c_str(), Package().c_str()); HashString const hashString(*type, hash); if (Base.empty() == false) @@ -226,7 +224,7 @@ bool debSrcRecordParser::Files(std::vector &List) // we haven't seen this file yet pkgSrcRecords::File F; F.Path = path; - F.FileSize = strtoull(size.c_str(), NULL, 10); + F.FileSize = size; F.Hashes.push_back(hashString); F.Hashes.FileSize(F.FileSize); -- cgit v1.2.3-70-g09d2