dotnet / machinelearning

ML.NET is an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
8.91k stars 1.86k forks source link

Possible bug in DoubleParser.cs #7181

Open lopango opened 1 week ago

lopango commented 1 week ago

In Microsoft.ML.Core\Utilities\DoubleParser.cs near lines 143 and 195

            int ichEnd;
            if (!DoubleParser.TryParse(span.Slice(ich, span.Length - ich), out value, out ichEnd, flags))
            {
                value = default(Double);
                return Result.Error;
            }

            // Make sure everything was consumed.
            while (ichEnd < span.Length)
            {
                if (!char.IsWhiteSpace(span[ichEnd]))
                    return Result.Extra;
                ichEnd++;
            }

the ichEnd is indexed on the sliced span. If ich is not 0 there will be an offset when for "ichEnd < span.Length" and "span[ichEnd]"

Example : for an input like " 1.234 " the method will return Result.Extra

Pössible solutions: