Fix Number.ParseNumber to not assume '\0' at the end of a span (#17808)
authorStephen Toub <stoub@microsoft.com>
Fri, 27 Apr 2018 22:37:09 +0000 (15:37 -0700)
committerGitHub <noreply@github.com>
Fri, 27 Apr 2018 22:37:09 +0000 (15:37 -0700)
commitd0a55af49fb03d064f7654ef6ee664b3eb384268
tree0c46463571df95bf1b48c4faa16789169e3aa201
parentacb110d3e9218bce176b411e32a22f8cb7abb1b0
Fix Number.ParseNumber to not assume '\0' at the end of a span (#17808)

* Fix Number.ParseNumber to not assume '\0' at the end of a span

This routine was written for parsing strings, which are implicitly null-terminated, and it doesn't factor in string length but instead uses tricks to exit loops when the next character is null.  Now that the routine is also used for spans, this is very problematic, as spans need not be null terminated, and generally aren't when they represent slices, and expecting a null termination like this can result in walking off the end of valid memory.

I would like to see all of this code rewritten to use span.  In the interim, though, as a short-term fix I've changed all dereferences of the current position to compare against the length of the span (or, rather, a pointer to the end), and pretend that a null terminator was found if we've hit the end.

* Address PR feedback
src/mscorlib/shared/System/Number.Parsing.cs