aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/qutil.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2023-12-25 16:51:40 +0100
committerJay Berkenbilt <ejb@ql.org>2023-12-25 17:17:17 +0100
commit6d4115b7c565b6750ba4649d120446a1bd2b5af2 (patch)
treec930f839d89b655ceb008d1a15e88094d36cb7b5 /libtests/qutil.cc
parent986d2485784d57d7a84cc5af50e67bde827b0dc9 (diff)
downloadqpdf-6d4115b7c565b6750ba4649d120446a1bd2b5af2.tar.zst
Detect overlong UTF-8 strings
Diffstat (limited to 'libtests/qutil.cc')
-rw-r--r--libtests/qutil.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/libtests/qutil.cc b/libtests/qutil.cc
index e882a33a..ca6ee314 100644
--- a/libtests/qutil.cc
+++ b/libtests/qutil.cc
@@ -266,6 +266,23 @@ to_utf8_test()
} catch (std::runtime_error& e) {
std::cout << "0x80000000: " << e.what() << std::endl;
}
+
+ // Overlong characters: characters represented by more bytes than necessary.
+ size_t pos = 0;
+ std::string utf8 = "\xC0\x80" // 1 << 7
+ "\xE0\x80\x80" // 1 << 11
+ "\xF0\x80\x80\x80" // 1 << 16
+ "\xF8\x80\x80\x80\x80" // 1 << 21
+ "\xFC\x80\x80\x80\x80\x80"; // 1 << 26
+ auto check = [&pos, &utf8](unsigned long wanted_pos) {
+ bool error = false;
+ assert(QUtil::get_next_utf8_codepoint(utf8, pos, error) == 0 && error && pos == wanted_pos);
+ };
+ check(2);
+ check(5);
+ check(9);
+ check(14);
+ check(20);
}
static void