Incorrect loop bound in SizeOptIListSelectIterator.ToList
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 64/100
Hướng nghiên cứu
Tìm SizeOptIListSelectIterator<TSource, TResult>.ToList() trong mã nguồn .NET runtime và đọc phần triển khai iterator được giới thiệu trong PR #118156. Tái hiện sự cố với <UseSizeOptimizedLinq>true</UseSizeOptimizedLinq> bằng ví dụ reflection được cung cấp. Công việc hoàn tất khi override trả về các mục đã chọn và kết quả khớp với việc liệt kê truy vấn thông thường; issue đề xuất sửa hoặc xóa đường dẫn không công khai này.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
SizeOptIListSelectIterator<TSource, TResult>.ToList() checks the destination list’s Count immediately after constructing it with a capacity. Since Count is zero, the loop never executes and the override returns an empty list for a nonempty source.
Admittedly, this path is non-public and functionally dead, but it hides a ticking time bomb, so would be nice to fix for good hygiene (or remove altogether)
Reproduction Steps
With true
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
IEnumerable<int> query = new[] { 1, 2, 3 }.Select(x => x * 10);
MethodInfo method = query.GetType().GetMethod(
"ToList",
BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
?? throw new InvalidOperationException("ToList override not found");
List<int> result = (List<int>)(method.Invoke(query, null)
?? throw new InvalidOperationException("ToList returned null"));
Console.WriteLine(query.GetType().Name);
Console.WriteLine($"Reflection: [{string.Join(", ", result)}]");
Console.WriteLine($"Public API: [{string.Join(", ", query.ToList())}]");
Expected behavior
printing [10, 20, 30], matching enumeration of the query
Actual behavior
prints []
Regression?
The erroneous loop was included when this iterator was introduced in #118156
Known Workarounds
No workaround is needed
Configuration
Windows 10, x64
Reproduced on .NET 10, 11 rc3 and main
Other information
List<TResult> list = new List<TResult>(_source.Count);
for (int i = 0; i < list.Count; i++)
{
list.Add(_selector(_source[i]));
}
return list;
The constructor initializes Capacity, not Count
- Ngôn ngữ chính
- C#
- Star
- 18.4k
- Fork
- 5.8k
- Merge trung bình
- 2 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 579
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của dotnet/runtime
-
DbTransaction.SupportsSavepoints docs say Release/ReleaseAsync are expected to throw, but they are no-ops by designCó thể đã có người làm @alaricd đã nhận 1 ngày trước. Đang mởarea-System.Transactions untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
dotnet/runtime#137040 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
FileSystemGlobbing: Matcher throws ArgumentOutOfRangeException when the rootDir is the same value as the fileCó thể đã có người làm @makazeu đã nhận 1 ngày trước. Đang mởarea-Extensions-FileSystem
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
dotnet/runtime#136989 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Configuration binder source generator emits unqualified List<T> when binding arrays without implicit usingsCó thể đã có người làm @makazeu đã nhận 1 ngày trước. Đang mởarea-Extensions-Configuration bug source-generator
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
dotnet/runtime#136972 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[wasi] .NET 10: WasmEnableSIMD with AOT fails because WasiApp.targets has -msimd128 commented outĐang mởarea-Build-mono untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
PropertyChangedEventArgs should have a nice DebuggerDisplayCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởarea-System.ComponentModel untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
dotnet/runtime#136608 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của dotnet/runtime
Issue tương tự
-
needs-triage
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 76/100
Azure/azure-sdk-for-net#64658 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
dotnet/aspnetcore#70370 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
NethermindEth/nethermind#15684 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area/ai-assistant squad/flyt
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Altinn/altinn-studio#21798 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
SubtitleEdit/subtitleedit#16699 ·
Maintainer thường phản hồi trong vòng 1 ngày