gerbera/2635.patch

124 lines
4.9 KiB
Diff

From 9e763df4e7be2e73c9b84001d85d0be8d8bb741c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Karl=20Strau=C3=9Fberger?= <k_straussberger@netzland.net>
Date: Tue, 17 May 2022 18:13:55 +0200
Subject: [PATCH] This and that
May even solve:
---
src/metadata/resolution.cc | 4 ++--
src/upnp_xml.cc | 4 ++--
src/util/process_executor.cc | 3 ++-
src/util/tools.cc | 14 ++++++++++++--
test/content/test_resolution.cc | 6 +++---
5 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/src/metadata/resolution.cc b/src/metadata/resolution.cc
index 031cb5788..476c644e5 100644
--- a/src/metadata/resolution.cc
+++ b/src/metadata/resolution.cc
@@ -33,7 +33,7 @@ Resolution::Resolution(const std::string& string)
if (!parts[0].empty()) {
auto x = stoulString(trimString(parts[0]));
- if (x == 0 || x == std::numeric_limits<unsigned int>::max()) {
+ if (x == 0 || x == std::numeric_limits<uint64_t>::max()) {
throw_std_runtime_error("Failed to parse '{}' to valid resolution", string);
}
_x = x;
@@ -41,7 +41,7 @@ Resolution::Resolution(const std::string& string)
if (!parts[1].empty()) {
auto y = stoulString(trimString(parts[1]));
- if (y == 0 || y == std::numeric_limits<unsigned int>::max()) {
+ if (y == 0 || y == std::numeric_limits<uint64_t>::max()) {
throw_std_runtime_error("Failed to parse '{}' to valid resolution", string);
}
_y = y;
diff --git a/src/upnp_xml.cc b/src/upnp_xml.cc
index d2d6bc60b..2ed9c7bef 100644
--- a/src/upnp_xml.cc
+++ b/src/upnp_xml.cc
@@ -508,9 +508,9 @@ std::string UpnpXMLBuilder::renderExtension(const std::string& contentType, cons
}
if (!location.empty() && location.has_extension()) {
- std::string extension = location.filename().extension();
+ std::string extension = urlEscape(location.filename().extension().string());
if (!language.empty())
- return fmt::format("{}.{}{}", urlExt, language, extension);
+ return fmt::format("{}.{}{}", urlExt, urlEscape(language), extension);
return fmt::format("{}{}", urlExt, extension);
}
diff --git a/src/util/process_executor.cc b/src/util/process_executor.cc
index 5f238058a..8557175fe 100644
--- a/src/util/process_executor.cc
+++ b/src/util/process_executor.cc
@@ -70,7 +70,8 @@ ProcessExecutor::ProcessExecutor(const std::string& command, const std::vector<s
log_debug("setenv: {}='{}'", eName, eValue);
}
log_debug("Launching process: {} {}", command, fmt::join(arglist, " "));
- execvp(command.c_str(), const_cast<char**>(argv.data()));
+ if (execvp(command.c_str(), const_cast<char**>(argv.data())))
+ log_error("Failed to execvp {} {}", command, fmt::join(arglist, " "));
break;
default:
break;
diff --git a/src/util/tools.cc b/src/util/tools.cc
index 119b74f5b..c549744be 100644
--- a/src/util/tools.cc
+++ b/src/util/tools.cc
@@ -118,7 +118,17 @@ unsigned long stoulString(const std::string& str, int def, int base)
if (str.empty() || (str[0] == '-' && !std::isdigit(*str.substr(1).c_str())) || (str[0] != '-' && !std::isdigit(*str.c_str())))
return def;
- return std::stoul(str, nullptr, base);
+ try {
+ std::size_t pos;
+ return std::stoul(str, &pos, base);
+ } catch (const std::invalid_argument& iaex) {
+ log_error("ia {} (input {})", iaex.what(), str);
+ } catch (const std::out_of_range& oorex) {
+ log_error("oor {} (input {})", oorex.what(), str);
+ } catch (const std::exception& ex) {
+ log_error("{} (input {})", ex.what(), str);
+ }
+ return def;
}
void reduceString(std::string& str, char ch)
@@ -252,7 +262,7 @@ std::string urlEscape(std::string_view str)
if ((i + cplen) > str.length())
cplen = 1;
- if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_' || c == '-') {
+ if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_' || c == '-' || c == '.') {
buf << char(c);
} else {
int hi = c >> 4;
diff --git a/test/content/test_resolution.cc b/test/content/test_resolution.cc
index 6d4a75610..c30c5c489 100644
--- a/test/content/test_resolution.cc
+++ b/test/content/test_resolution.cc
@@ -3,10 +3,10 @@
#include "metadata//resolution.h"
TEST(ResolutionTest, parse) {
- auto res = Resolution("122586668x54589448448485");
+ auto res = Resolution("122586668x448448485");
EXPECT_EQ(res.x(), 122586668);
- EXPECT_EQ(res.y(), 54589448448485);
+ EXPECT_EQ(res.y(), 448448485);
}
TEST(ResolutionTest, parseWithSpace) {
@@ -38,4 +38,4 @@ TEST(ResolutionTest, throwOnBad) {
EXPECT_THROW(Resolution("0x"), std::runtime_error);
EXPECT_THROW(Resolution("0x1"), std::runtime_error);
EXPECT_THROW(Resolution("1x0"), std::runtime_error);
-}
\ No newline at end of file
+}