From b47d069bf8f5e3bbe18b142d45efd630e6af118b Mon Sep 17 00:00:00 2001 From: Akash Kumar <116457960+akashchamp@users.noreply.github.com> Date: Wed, 28 Oct 2026 20:06:17 +0530 Subject: [PATCH] [piper] do not index past the end for an empty demuxed body When a demuxed line has an empty body, like a blank docker-compose line "db-1 | ", the memcpy() destination in piper_log_format::get_subline() was &plf_cached_line[prefix_len], which is one past the end of the vector. Builds with -D_GLIBCXX_ASSERTIONS (Arch Linux, for one) abort on that. Use data() + prefix_len instead. Fixes #1759 --- src/log_format_impls.cc | 5 +++-- test/Makefile.am | 1 + ...est_demux.sh_83e339125bf0af442ee46a6f498cb750cda01d5f.err | 0 ...est_demux.sh_83e339125bf0af442ee46a6f498cb750cda01d5f.out | 2 ++ test/logfile_docker_compose_empty_body.0 | 2 ++ test/test_demux.sh | 3 +++ 6 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 test/expected/test_demux.sh_83e339125bf0af442ee46a6f498cb750cda01d5f.err create mode 100644 test/expected/test_demux.sh_83e339125bf0af442ee46a6f498cb750cda01d5f.out create mode 100644 test/logfile_docker_compose_empty_body.0 diff --git a/src/log_format_impls.cc b/src/log_format_impls.cc index 6b4caa99ba2..3c8371e7c4f 100644 --- a/src/log_format_impls.cc +++ b/src/log_format_impls.cc @@ -123,8 +123,9 @@ class piper_log_format : public log_format { const auto prefix_len = this->plf_cached_line.size(); this->plf_cached_line.resize(this->plf_cached_line.size() + sbr.length()); - memcpy( - &this->plf_cached_line[prefix_len], sbr.get_data(), sbr.length()); + memcpy(this->plf_cached_line.data() + prefix_len, + sbr.get_data(), + sbr.length()); sbr.share(this->plf_share_manager, this->plf_cached_line.data(), diff --git a/test/Makefile.am b/test/Makefile.am index 2bccff7da21..ecae9447f8b 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -363,6 +363,7 @@ dist_noinst_DATA = \ logfile_cloudflare.1 \ logfile_cxx.0 \ logfile_docker_compose.0 \ + logfile_docker_compose_empty_body.0 \ logfile_docker_compose_with_noise.0 \ logfile_docker_compose_with_ts.0 \ logfile_dst.0 \ diff --git a/test/expected/test_demux.sh_83e339125bf0af442ee46a6f498cb750cda01d5f.err b/test/expected/test_demux.sh_83e339125bf0af442ee46a6f498cb750cda01d5f.err new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/expected/test_demux.sh_83e339125bf0af442ee46a6f498cb750cda01d5f.out b/test/expected/test_demux.sh_83e339125bf0af442ee46a6f498cb750cda01d5f.out new file mode 100644 index 00000000000..8fbc490ce5a --- /dev/null +++ b/test/expected/test_demux.sh_83e339125bf0af442ee46a6f498cb750cda01d5f.out @@ -0,0 +1,2 @@ +2013-06-06T19:13:20.123456+0000 +2013-06-06T19:13:20.123456+0000 hello diff --git a/test/logfile_docker_compose_empty_body.0 b/test/logfile_docker_compose_empty_body.0 new file mode 100644 index 00000000000..a6a8a2592e6 --- /dev/null +++ b/test/logfile_docker_compose_empty_body.0 @@ -0,0 +1,2 @@ +db-1 | +db-1 | hello diff --git a/test/test_demux.sh b/test/test_demux.sh index 0227030a9ce..c37024ca5fe 100644 --- a/test/test_demux.sh +++ b/test/test_demux.sh @@ -19,6 +19,9 @@ cat ${test_dir}/logfile_docker_compose_with_ts.0 | run_cap_test env TEST_COMMENT run_cap_test ${lnav_test} -n ${test_dir}/logfile_docker_compose_with_ts.0 +# The first message has an empty body +run_cap_test ${lnav_test} -n ${test_dir}/logfile_docker_compose_empty_body.0 + run_cap_test ${lnav_test} -n ${test_dir}/logfile_mux_zookeeper.0 run_cap_test ${lnav_test} -n \