Replace zend_object object with its header to prevent the "using flexible array in the middle of another struct" problem in its inheritted classes (static analyzer report)
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C
- Star
- 40.4k
- Fork
- 8.2k
- Merge trung bình
- 2 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 96
Mô tả
Class zend_object is defined as a flexible array of length 1. The flexible array defined with size 1 and 0 is not the standard behavior. It is suggested to use the unsized definition (https://people.kernel.org/kees/bounded-flexible-arrays-in-c). Besides, not all its subclasses will use the array field properties_table of the zend_object class. If I understand the code correctly, when the properties_table[0] field is not used, it will store a ZVAL_UNDEF zval indicating the end of the iteration. Whereas when the properties_table[0] field is used, the flags and array length are checked first before accessing the data in the array.
If the properties_table[0] field is not used in these sub-classes, will it be better to replace the zend_object in these classes with only the header part of zend_object?
i.e. (as suggested in case 2 of https://lpc.events/event/18/contributions/1722/attachments/1591/3303/Wfamnae_lpceu2024.pdf)
We can define another struct with only the header part (let's name it zend_object_header_part), but leave the zend_object struct with both the header and the flexible array part.
When only the header is needed, we can use the zend_object_header_part (e.g. in the class inheritance), whereas for those requiring the array part, or using the object through a zend_object pointer, we can still use the full definition.
Usages of zend_object in the middle of other structs whose array field is potentially never used through the composite struct:
- https://github.com/php/php-src/blob/c2fddac8ca2c13b53dfe1044e9355355ae602e30/Zend/zend_generators.h#L58-L59
- https://github.com/php/php-src/blob/c2fddac8ca2c13b53dfe1044e9355355ae602e30/Zend/zend_interfaces.c#L490-L491
- https://github.com/php/php-src/blob/c2fddac8ca2c13b53dfe1044e9355355ae602e30/Zend/zend_closures.c#L31-L32
- https://github.com/php/php-src/blob/c2fddac8ca2c13b53dfe1044e9355355ae602e30/Zend/zend_fibers.h#L102-L104
- https://github.com/php/php-src/blob/c2fddac8ca2c13b53dfe1044e9355355ae602e30/Zend/zend_iterators.h#L64-L65
- https://github.com/php/php-src/blob/c2fddac8ca2c13b53dfe1044e9355355ae602e30/ext/opcache/jit/zend_jit_ir.c#L8451-L8452
- https://github.com/php/php-src/blob/c2fddac8ca2c13b53dfe1044e9355355ae602e30/ext/com_dotnet/com_saproxy.c#L35-L36
- https://github.com/php/php-src/blob/c2fddac8ca2c13b53dfe1044e9355355ae602e30/ext/com_dotnet/php_com_dotnet_internal.h#L28-L29
- https://github.com/php/php-src/blob/c2fddac8ca2c13b53dfe1044e9355355ae602e30/ext/com_dotnet/com_persist.c#L278-L279
- https://github.com/php/php-src/blob/c2fddac8ca2c13b53dfe1044e9355355ae602e30/ext/ffi/ffi.c#L169-L170
- https://github.com/php/php-src/blob/c2fddac8ca2c13b53dfe1044e9355355ae602e30/ext/ffi/ffi.c#L191-L192
- https://github.com/php/php-src/blob/c2fddac8ca2c13b53dfe1044e9355355ae602e30/ext/ffi/ffi.c#L199-L200
- https://github.com/php/php-src/blob/c2fddac8ca2c13b53dfe1044e9355355ae602e30/ext/pdo/php_pdo_driver.h#L645-L646
- https://github.com/php/php-src/blob/c2fddac8ca2c13b53dfe1044e9355355ae602e30/ext/zend_test/fiber.h#L24-L25
- https://github.com/php/php-src/blob/c2fddac8ca2c13b53dfe1044e9355355ae602e30/ext/intl/normalizer/normalizer_class.h#L25-L26
- https://github.com/php/php-src/blob/c2fddac8ca2c13b53dfe1044e9355355ae602e30/ext/intl/locale/locale_class.h#L25-L26
report ids: 250106-1639:1-6,8-17 (16 reports in total)
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.
Hướng nghiên cứu
Bắt đầu với định nghĩa zend_object và so sánh các cách sử dụng đã được kiểm tra trong Zend/zend_generators.h và ext/pdo/php_pdo_driver.h với các struct tổng hợp chưa được kiểm tra được liệt kê trong Zend và ext. Xác định những lớp nào cần properties_table, sau đó giữ lại đối tượng đầy đủ ở nơi cần thiết và sử dụng biểu diễn chỉ chứa header ở những nơi khác. Hoàn thành khi xử lý được các báo cáo static-analyzer đã liệt kê mà không thay đổi hành vi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- c, php
- Lĩnh vực
- compilers
- Loại issue
- Tái cấu trúc
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100