From 7a5dfc8cc1458b5b7ea0330c7d59030230322b6c Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Tue, 25 Aug 2026 11:37:23 +0300 Subject: [PATCH] Fix unicode XML parsing IB-9086 Signed-off-by: Raul Metsma --- CMakeLists.txt | 2 +- src/XMLDocument.h | 3 ++- src/crypto/TSL.cpp | 2 +- test/libdigidocpp_boost.cpp | 15 +++++++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b4eadf12..119083633 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ endif() if(POLICY CMP0177) cmake_policy(SET CMP0177 NEW) endif() -project(libdigidocpp VERSION 4.5.0 +project(libdigidocpp VERSION 4.5.1 DESCRIPTION "C++ library for digital signatures and validation of digitally signed documents" HOMEPAGE_URL https://github.com/open-eid/libdigidocpp ) diff --git a/src/XMLDocument.h b/src/XMLDocument.h index 6c046149d..fd1d57c61 100644 --- a/src/XMLDocument.h +++ b/src/XMLDocument.h @@ -21,6 +21,7 @@ #include "crypto/Digest.h" #include "crypto/X509Cert.h" +#include "util/File.h" #include "util/log.h" #include "util/memory.h" @@ -369,7 +370,7 @@ struct XMLDocument: public unique_free_d, public XMLNode { if(path.empty()) return; - if(std::ifstream f{path}) + if(std::ifstream f{util::File::encodeName(path), std::ifstream::binary}) *this = openStream(f, n); } diff --git a/src/crypto/TSL.cpp b/src/crypto/TSL.cpp index 7a5901cb3..7c042101b 100644 --- a/src/crypto/TSL.cpp +++ b/src/crypto/TSL.cpp @@ -609,7 +609,7 @@ bool TSL::validateRemoteDigest(const string &url) } Digest sha(URI_SHA256); - ifstream is(path, ifstream::binary); + ifstream is(File::encodeName(path), ifstream::binary); sha.update(is); if(!digest.empty() && digest != sha.result()) diff --git a/test/libdigidocpp_boost.cpp b/test/libdigidocpp_boost.cpp index 9b0d9674a..1af2c63cf 100644 --- a/test/libdigidocpp_boost.cpp +++ b/test/libdigidocpp_boost.cpp @@ -751,6 +751,21 @@ BOOST_AUTO_TEST_CASE(XMLBomb) if(std::fstream f{"xml-bomb-cont.xml"}) BOOST_CHECK_THROW(XMLDocument::openStream(f, {}, true), Exception); } +BOOST_AUTO_TEST_CASE(XMLUnicodePath) +{ + const string path = "libdigidocpp-\xC3\xB5-\xC3\xA4-\xC3\xB6-\xC3\xBC.xml"; + { + ofstream out{util::File::encodeName(path), ofstream::binary|ofstream::trunc}; + BOOST_REQUIRE(out.is_open()); + out << "unicode path"; + BOOST_REQUIRE(out.good()); + } + + XMLDocument doc(path, {"root"}); + BOOST_CHECK(doc); + BOOST_CHECK_EQUAL(string_view(doc), "unicode path"); + fs::remove(util::File::encodeName(path)); +} BOOST_AUTO_TEST_CASE(XMLXXE) { BOOST_REQUIRE(fs::exists("xxe-sentinel.txt"));