From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Cc: goldstein.w.n@gmail.com, amonakov@ispras.ru,
"H . J . Lu" <hjl.tools@gmail.com>
Subject: [PATCH v3 0/2] Improve wcsstr
Date: Fri, 15 Mar 2024 14:23:44 -0300 [thread overview]
Message-ID: <20240315172346.2484542-1-adhemerval.zanella@linaro.org> (raw)
Different than strstr, wcsstr still uses an O(m*n) algorithm that might
be considered a security issue (although BZ 23865 was marked security-
since there is no actual application impact).
The gnulib recently added a wrapper to fix it [1] and it is used as the
base de str-two-way.h implementation. This patch adds a similar
implementation, and different than strstr, neither the "shift table"
optimization nor the self-adapting filtering check is used because it
would result in a too-large shift table (and it also simplifies the
implementation bit). The patchset also added a proper tests for wcsstr,
based on strstr one.
With this fix, and with the removal of the powerpc strcasestr
optimization [2], it seems that only x86_64 still provides a non
O(m*n) implementation [3]. Noah already gave a +1, so it would be
good to have some confirmation that this implementation can really
show some quadradic behaviour before propose a removal.
[1] https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=commit;h=9411c5e467cf60f6295b9fed306029f341a0f24f
[2] https://sourceware.org/git/?p=glibc.git;a=commit;h=4a76fb1da8b7e7fa472741921f49ef32f81bc0a0
[3] https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86_64/multiarch/strstr-avx512.c;h=3ac53accbdde0b400dfd19a2070fbb579aff4177;hb=4a76fb1da8b7e7fa472741921f49ef32f81bc0a0
Changes from v2:
* Remove the test repetition.
Changes from v1:
* Add more tests from gnulib.
* Removed unused macros from wcsstr.
Adhemerval Zanella (2):
wcsmbs: Add test-wcsstr
wcsmbs: Ensure wcstr worst-case linear execution time (BZ 23865)
string/test-strstr.c | 314 +++++++++++++++++++++++++++++++++++--------
wcsmbs/Makefile | 1 +
wcsmbs/test-wcsstr.c | 20 +++
wcsmbs/wcs-two-way.h | 312 ++++++++++++++++++++++++++++++++++++++++++
wcsmbs/wcsstr.c | 103 +++++---------
5 files changed, 624 insertions(+), 126 deletions(-)
create mode 100644 wcsmbs/test-wcsstr.c
create mode 100644 wcsmbs/wcs-two-way.h
--
2.34.1
next reply other threads:[~2024-03-15 17:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-15 17:23 Adhemerval Zanella [this message]
2024-03-15 17:23 ` [PATCH v3 1/2] wcsmbs: Add test-wcsstr Adhemerval Zanella
2024-03-16 1:25 ` DJ Delorie
2024-03-16 1:25 ` DJ Delorie
2024-03-15 17:23 ` [PATCH v3 2/2] wcsmbs: Ensure wcstr worst-case linear execution time (BZ 23865) Adhemerval Zanella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240315172346.2484542-1-adhemerval.zanella@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=amonakov@ispras.ru \
--cc=goldstein.w.n@gmail.com \
--cc=hjl.tools@gmail.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).