Native mode: a runtime zero divisor or PHP_INT_MIN % -1 kills the process (SIGFPE)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
Start with the native-mode lowering for %, /, << and >>, comparing its runtime behavior with php::fn::intdiv() and the existing static undefined-behavior checks. Use the issue's zero-divisor, PHP_INT_MIN, and invalid-shift examples with UBSan; done means runtime cases no longer terminate the process and produce the specified PHP errors or result.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Since 0.8.0 native int storage is the default, so % and / on plain int values lower to the raw C++ operators. When the divisor is only known at runtime, PHP's catchable errors become a crash of the whole process:
<?php
function mod(int $a, int $b): int { return $a % $b; }
function main(): void
{
try {
var_dump(mod(5, 0));
} catch (DivisionByZeroError $e) {
echo $e->getMessage(), "\n"; // PHP: "Modulo by zero"
}
}
Floating point exception (core dumped)
runtime operation (int params) |
PHP | TypePHP native mode |
|---|---|---|
$a % $b, $b = 0 |
DivisionByZeroError |
SIGFPE, process dies |
$a / $b, $b = 0 |
DivisionByZeroError |
SIGFPE |
PHP_INT_MIN % -1 |
0 |
SIGFPE |
PHP_INT_MIN / -1 |
float(9.2233720368547758E+18) |
SIGFPE |
$a << $b, $b = 64 |
0 |
1 (x86 masks the count) |
$a << $b, $b = -1 |
ArithmeticError |
PHP_INT_MIN |
I understand this is the documented trade-off ("Native std::int overflow and integer division behavior — Intentional Rule"), that use varint_types keeps PHP semantics, and that #45's guards were moved to varint mode on purpose in 2166e1a. The compiler already rejects all of these when they are statically detectable ("has undefined behavior in C++ native mode"), which suggests the runtime form is a gap rather than a goal. A few points that may be worth weighing now that native is the default:
- Overflow vs. crash. Overflow and integer division change a value; these cases terminate the process, bypass
try/catch, and in a server take every request with them. A zero divisor coming from input is common. - They are undefined behavior, not just a different result. With
--sanitize undefinedUBSan reports each of them (division by zero,division of -9223372036854775808 by -1 cannot be represented,shift exponent 64 is too large,shift exponent -1 is negative), so the optimizer is free to assume they never happen. - The guard is cheap.
php::fn::intdiv()already implements exactly these checks; for%//it is one well-predicted compare on the divisor, and it can be skipped whenever the divisor is a non-zero, non--1constant, which the compiler already knows. Shifts need one compare on the count.
Would you accept a change that keeps native storage and native arithmetic, but adds these runtime checks to %, /, << and >> (throwing the same DivisionByZeroError / ArithmeticError as PHP, and returning 0 for PHP_INT_MIN % -1)? If raw speed matters for specific code, std::int() could remain the explicit no-check opt-in, as it is today for constant divisors. Happy to implement it with benchmarks if that direction is acceptable.
- Ngôn ngữ chính
- PHP
- Star
- 1.4k
- Fork
- 80
- Merge trung bình
- 1 ngày 35 phút
- Pull request đã merge (30 ngày)
- 24
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
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 swoole/typephp
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
NoExport by-defaultĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 1 ngày
-
~ converts string and bool operands to intCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Bool operands: relational comparison, unary minus and division behave numericallyCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Side effects run out of order in echo lists and array literal keysCó thể đã có người làm @Giandonn đã nhận 5 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của swoole/typephp
Issue tương tự
-
Bug Enhancement Performance
Độ 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
-
Feature Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Maintainer thường phản hồi trong vòng 1 ngày
-
frontend low-priority
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
mplodowski/dynamicpdf-plugin#336 ·
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 68/100
AdvancedCustomFields/acf#1044 ·
-
Add ZammadCó thể đã có người làm @Arslan-TR đã nhận hôm nay. Đang mởrequest
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
endoflife-date/endoflife.date#11298 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày