[GH-ISSUE #734] PHP8 - Fatal error with some imap attachments? #459

Closed
opened 2026-02-25 21:35:05 +03:00 by kerem · 7 comments
Owner

Originally created by @mcbmcb0 on GitHub (Jul 21, 2023).
Original GitHub issue: https://github.com/cypht-org/cypht/issues/734

💬 Question

I've put this as a questions tho I think its a bug due to php making count types compulsory. but I don't know how to reliably reproduce it:

PHP Fatal error:  Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /var/www/cypht/modules/imap/functions.php:914
Stack trace:
#0 /var/www/cypht/modules/imap/functions.php(476): get_imap_part_name()
#1 /var/www/cypht/modules/imap/functions.php(410): get_part_desc()
#2 /var/www/cypht/modules/imap/functions.php(534): format_msg_part_row()
#3 /var/www/cypht/modules/imap/functions.php(540): format_msg_part_section()
#4 /var/www/cypht/modules/imap/output_modules.php(152): format_msg_part_section()
#5 /var/www/cypht/lib/module.php(526): Hm_Output_filter_message_struct->output()
#6 /var/www/cypht/lib/modules_exec.php(96): Hm_Output_Module->output_content()
#7 /var/www/cypht/lib/modules_exec.php(83): Hm_Module_Exec->process_result()
#8 /var/www/cypht/lib/modules_exec.php(43): Hm_Module_Exec->run_output_module()
#9 /var/www/cypht/lib/dispatch.php(235): Hm_Module_Exec->run_output_modules()
#10 /var/www/cypht/lib/dispatch.php(190): Hm_Dispatch->process_request()
#11 /var/www/cypht/site/index.php(50): Hm_Dispatch->__construct()
#12 {main}\n  thrown in /var/www/cypht/modules/imap/functions.php on line 914

the offending code is:
for ($i=0;$i<count($struct['disposition']['attachment']);$i++) {
I assume there are no attachments tho they are expected. This line has not been updated in the latest current release. I've hacked a quick fix until someone can replicate this and/or patch it:
for ($i=0;$i<count( is_countable($struct['disposition']['attachment']??null) ? $struct['disposition']['attachment']: [] );$i++) {

thanks

Originally created by @mcbmcb0 on GitHub (Jul 21, 2023). Original GitHub issue: https://github.com/cypht-org/cypht/issues/734 ## 💬 Question <!-- Describe your Question in detail. Include screenshots and drawings if needed. --> I've put this as a questions tho I think its a bug due to php making count types compulsory. but I don't know how to reliably reproduce it: ``` PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /var/www/cypht/modules/imap/functions.php:914 Stack trace: #0 /var/www/cypht/modules/imap/functions.php(476): get_imap_part_name() #1 /var/www/cypht/modules/imap/functions.php(410): get_part_desc() #2 /var/www/cypht/modules/imap/functions.php(534): format_msg_part_row() #3 /var/www/cypht/modules/imap/functions.php(540): format_msg_part_section() #4 /var/www/cypht/modules/imap/output_modules.php(152): format_msg_part_section() #5 /var/www/cypht/lib/module.php(526): Hm_Output_filter_message_struct->output() #6 /var/www/cypht/lib/modules_exec.php(96): Hm_Output_Module->output_content() #7 /var/www/cypht/lib/modules_exec.php(83): Hm_Module_Exec->process_result() #8 /var/www/cypht/lib/modules_exec.php(43): Hm_Module_Exec->run_output_module() #9 /var/www/cypht/lib/dispatch.php(235): Hm_Module_Exec->run_output_modules() #10 /var/www/cypht/lib/dispatch.php(190): Hm_Dispatch->process_request() #11 /var/www/cypht/site/index.php(50): Hm_Dispatch->__construct() #12 {main}\n thrown in /var/www/cypht/modules/imap/functions.php on line 914 ``` the offending code is: `for ($i=0;$i<count($struct['disposition']['attachment']);$i++) {` I assume there are no attachments tho they are expected. This line has not been updated in the latest current release. I've hacked a quick fix until someone can replicate this and/or patch it: `for ($i=0;$i<count( is_countable($struct['disposition']['attachment']??null) ? $struct['disposition']['attachment']: [] );$i++) { ` thanks
kerem closed this issue 2026-02-25 21:35:05 +03:00
Author
Owner

@marclaporte commented on GitHub (Jul 23, 2023):

@josaphatim What do you think?

<!-- gh-comment-id:1646893390 --> @marclaporte commented on GitHub (Jul 23, 2023): @josaphatim What do you think?
Author
Owner

@josaphatim commented on GitHub (Jul 31, 2023):

@josaphatim What do you think?

@mcbmcb0, @marclaporte I couldn't really reproduce that by as error is clear I'll proposed a merge request

<!-- gh-comment-id:1658810088 --> @josaphatim commented on GitHub (Jul 31, 2023): > @josaphatim What do you think? @mcbmcb0, @marclaporte I couldn't really reproduce that by as error is clear I'll proposed a merge request
Author
Owner

@marclaporte commented on GitHub (Sep 5, 2023):

@mcbmcb0 Please confirm the issue is solved in master.

<!-- gh-comment-id:1705812776 --> @marclaporte commented on GitHub (Sep 5, 2023): @mcbmcb0 Please confirm the issue is solved in master.
Author
Owner

@mcbmcb0 commented on GitHub (Sep 8, 2023):

Hi
while I still don't know how to force the error, the current master appears to work for me on php8.2 / debian 12.
thanks!

EDIT: but i do now notice:
PHP Warning: foreach() argument must be of type array|object, int given in /var/www/cypht/modules/imap/functions.php on line 1390, referer: https://XXXXXX/admin/cypht
unfortunately i haven't had time to look into it.

<!-- gh-comment-id:1711102910 --> @mcbmcb0 commented on GitHub (Sep 8, 2023): Hi while I still don't know how to force the error, the current master appears to work for me on php8.2 / debian 12. thanks! EDIT: but i do now notice: `PHP Warning: foreach() argument must be of type array|object, int given in /var/www/cypht/modules/imap/functions.php on line 1390, referer: https://XXXXXX/admin/cypht` unfortunately i haven't had time to look into it.
Author
Owner

@josaphatim commented on GitHub (Sep 9, 2023):

modules/imap/functions.php

This is the fix for it https://github.com/cypht-org/cypht/pull/759.

<!-- gh-comment-id:1712561533 --> @josaphatim commented on GitHub (Sep 9, 2023): > modules/imap/functions.php This is the fix for it https://github.com/cypht-org/cypht/pull/759.
Author
Owner

@marclaporte commented on GitHub (Sep 9, 2023):

@mcbmcb0 Please confirm the issue is solved in master.

<!-- gh-comment-id:1712583494 --> @marclaporte commented on GitHub (Sep 9, 2023): @mcbmcb0 Please confirm the issue is solved in master.
Author
Owner

@mcbmcb0 commented on GitHub (Sep 9, 2023):

yes, this issue now resolved. thanks

<!-- gh-comment-id:1712637540 --> @mcbmcb0 commented on GitHub (Sep 9, 2023): yes, this issue now resolved. thanks
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/cypht#459
No description provided.