public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* Re: my strstr is broken
@ 2018-09-12 13:11 Wilco Dijkstra
  0 siblings, 0 replies; 5+ messages in thread
From: Wilco Dijkstra @ 2018-09-12 13:11 UTC (permalink / raw)
  To: adhemerval.zanella; +Cc: nd, libc-alpha

Adhemerval wrote:
> On 11/09/2018 15:46, Wilco Dijkstra wrote:
>> Siddhesh wrote:
>> 
>>> Is this a non-x86 architecture?  I can reproduce this on the glibc
>>> 2.28 tag when I hack the ifunc resolver to ignore
>>> __strstr_sse2_unaligned and always use the stock __strstr.
>> 
>> It's the generic strstr indeed. The issue is due to the long needle code using
>> the same AVAILABLE macro as for short needles. Since the macro now 
>> ensures the haystack contains up to 512 valid characters, it cannot handle
>> needles which are longer than this. The fix is easy, just add the needle length.
>> I'll post a patch.
>
> Does it affect memmem as well? It would be useful to check it the tests
> are inadequate and fix them if the case for memmem.

Strcasestr uses the same readahead mechanism, but memmem is fine since it
doesn't use null-terminated strings. The issue is due to trying to avoid calling strlen
on the whole string - it's not obvious that's worth the increase in complexity.

Wilco

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: my strstr is broken
  2018-09-11 18:46 Wilco Dijkstra
@ 2018-09-11 19:42 ` Adhemerval Zanella
  0 siblings, 0 replies; 5+ messages in thread
From: Adhemerval Zanella @ 2018-09-11 19:42 UTC (permalink / raw)
  To: libc-alpha



On 11/09/2018 15:46, Wilco Dijkstra wrote:
> Siddhesh wrote:
> 
>> Is this a non-x86 architecture?  I can reproduce this on the glibc
>> 2.28 tag when I hack the ifunc resolver to ignore
>> __strstr_sse2_unaligned and always use the stock __strstr.
> 
> It's the generic strstr indeed. The issue is due to the long needle code using
> the same AVAILABLE macro as for short needles. Since the macro now 
> ensures the haystack contains up to 512 valid characters, it cannot handle
> needles which are longer than this. The fix is easy, just add the needle length.
> I'll post a patch.

Does it affect memmem as well? It would be useful to check it the tests
are inadequate and fix them if the case for memmem.

> 
>> It looks like the test case is fixed on trunk, with[1], but I'll take
>> a closer look at it later to confirm.
> 
> No it still exists on trunk, but you need avoid tests with a trivial first match
> which is now handled early as a special case. Also to make it fail consistently
> the needle needs to be longer than 1024 characters. Unfortunately neither the
> tests or benchmarks ever call two_way_long_needle...
> 
> Wilco
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: my strstr is broken
@ 2018-09-11 18:46 Wilco Dijkstra
  2018-09-11 19:42 ` Adhemerval Zanella
  0 siblings, 1 reply; 5+ messages in thread
From: Wilco Dijkstra @ 2018-09-11 18:46 UTC (permalink / raw)
  To: siddhesh.poyarekar; +Cc: brunni, cottrell, libc-alpha, libc-help, nd

Siddhesh wrote:

> Is this a non-x86 architecture?  I can reproduce this on the glibc
> 2.28 tag when I hack the ifunc resolver to ignore
> __strstr_sse2_unaligned and always use the stock __strstr.

It's the generic strstr indeed. The issue is due to the long needle code using
the same AVAILABLE macro as for short needles. Since the macro now 
ensures the haystack contains up to 512 valid characters, it cannot handle
needles which are longer than this. The fix is easy, just add the needle length.
I'll post a patch.

> It looks like the test case is fixed on trunk, with[1], but I'll take
> a closer look at it later to confirm.

No it still exists on trunk, but you need avoid tests with a trivial first match
which is now handled early as a special case. Also to make it fail consistently
the needle needs to be longer than 1024 characters. Unfortunately neither the
tests or benchmarks ever call two_way_long_needle...

Wilco

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: my strstr is broken
  2018-09-11 15:21             ` Paul Pluzhnikov
@ 2018-09-11 15:38               ` Siddhesh Poyarekar
  0 siblings, 0 replies; 5+ messages in thread
From: Siddhesh Poyarekar @ 2018-09-11 15:38 UTC (permalink / raw)
  To: Paul Pluzhnikov; +Cc: brunni, cottrell, libc-help, GLIBC Devel

On Tuesday 11 September 2018 08:51 PM, Paul Pluzhnikov wrote:
> This is the second time in my (short) memory strstr got broken with
> very long inputs
> (https://sourceware.org/bugzilla/show_bug.cgi?id=12092).
> There was also https://sourceware.org/bugzilla/show_bug.cgi?id=14602
> 
> It seems that testing of strstr is entirely inadequate: (AFAICT) we
> only test the IFUNC-selected version, and only on small set of inputs.

I'm not sure about the assertion about not testing IFUNC versions (since 
only x86_64 and powerpc seem to be using them and their IFUNC_IMPL 
macros look correct to me and should trigger all variants provided the 
hardware supports it) but a stress test would be most welcome.

Thanks,
Siddhesh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: my strstr is broken
       [not found]           ` <CAAHN_R1PBjz=+NsoA=XCdKcWCi+A-BaG=f29tM9aqyp7+CC_Aw@mail.gmail.com>
@ 2018-09-11 15:21             ` Paul Pluzhnikov
  2018-09-11 15:38               ` Siddhesh Poyarekar
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Pluzhnikov @ 2018-09-11 15:21 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: brunni, cottrell, libc-help, GLIBC Devel

+cc libc-alpha

On Tue, Sep 11, 2018 at 7:51 AM Siddhesh Poyarekar
<siddhesh.poyarekar@gmail.com> wrote:

> The stock __strstr has a bug, which seems to have been fixed on master
> with the commit I mentioned.

This is the second time in my (short) memory strstr got broken with
very long inputs
(https://sourceware.org/bugzilla/show_bug.cgi?id=12092).
There was also https://sourceware.org/bugzilla/show_bug.cgi?id=14602

It seems that testing of strstr is entirely inadequate: (AFAICT) we
only test the IFUNC-selected version, and only on small set of inputs.

I filed https://sourceware.org/bugzilla/show_bug.cgi?id=23631


-- 
Paul Pluzhnikov

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-09-12 13:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-12 13:11 my strstr is broken Wilco Dijkstra
  -- strict thread matches above, loose matches on Subject: below --
2018-09-11 18:46 Wilco Dijkstra
2018-09-11 19:42 ` Adhemerval Zanella
     [not found] <20180910144752.GA29636@netestate.de>
     [not found] ` <20180911102711.GA31876@netestate.de>
     [not found]   ` <alpine.LNX.2.21.1809110851590.32470@robroy>
     [not found]     ` <20180911135401.GA1745@netestate.de>
     [not found]       ` <CAAHN_R3e0rEgUK5vyKb55QEKmO6+mFVwUQ11w3Ujn97cnmMwkg@mail.gmail.com>
     [not found]         ` <20180911144138.GA2030@netestate.de>
     [not found]           ` <CAAHN_R1PBjz=+NsoA=XCdKcWCi+A-BaG=f29tM9aqyp7+CC_Aw@mail.gmail.com>
2018-09-11 15:21             ` Paul Pluzhnikov
2018-09-11 15:38               ` Siddhesh Poyarekar

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).