Skip to content

Commit 0076b47

Browse files
committed
Fix Bug #80438: imap_msgno() incorrectly warns and return false on valid UIDs in PHP 8.0.0
Checking for a valid Unique ID (UID) cannot use the convenience macro as they might be larger than the message number which has for maximum value the total number of current messages available in the mailbox.
1 parent a55402d commit 0076b47

File tree

3 files changed

+83
-4
lines changed

3 files changed

+83
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ PHP NEWS
1313
- Fileinfo:
1414
. Fixed bug #77961 (finfo_open crafted magic parsing SIGABRT). (cmb)
1515

16+
- IMAP
17+
. Fixed bug #80438 (imap_msgno() incorrectly warns and return false on valid UIDs in PHP 8.0.0). (girgias)
18+
1619
- Intl:
1720
. Fixed bug #80425 (MessageFormatAdapter::getArgTypeList redefined). (Nikita)
1821

ext/imap/php_imap.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,20 +2835,24 @@ PHP_FUNCTION(imap_uid)
28352835
PHP_FUNCTION(imap_msgno)
28362836
{
28372837
zval *streamind;
2838-
zend_long msgno;
2838+
zend_long msg_uid;
28392839
pils *imap_le_struct;
28402840

2841-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &streamind, &msgno) == FAILURE) {
2841+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &streamind, &msg_uid) == FAILURE) {
28422842
RETURN_THROWS();
28432843
}
28442844

28452845
if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) {
28462846
RETURN_THROWS();
28472847
}
28482848

2849-
PHP_IMAP_CHECK_MSGNO(msgno, 2);
2849+
/* Do NOT use the PHP_IMAP_CHECK_MSGNO() macro as UID cannot be checked for their upper bound. */
2850+
if (msg_uid < 1) {
2851+
zend_argument_value_error(2, "must be greater than 0");
2852+
RETURN_THROWS();
2853+
}
28502854

2851-
RETURN_LONG(mail_msgno(imap_le_struct->imap_stream, msgno));
2855+
RETURN_LONG(mail_msgno(imap_le_struct->imap_stream, msg_uid));
28522856
}
28532857
/* }}} */
28542858

ext/imap/tests/bug80438.phpt

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
--TEST--
2+
Bug #80438: imap_msgno() incorrectly warns and return false on valid UIDs in PHP 8.0.0
3+
--SKIPIF--
4+
<?php
5+
require_once(__DIR__.'/setup/skipif.inc');
6+
?>
7+
--FILE--
8+
<?php
9+
echo "*** Testing imap_fetch_overview() : basic functionality ***\n";
10+
11+
require_once __DIR__.'/setup/imap_include.inc';
12+
13+
// create a new mailbox and add 10 new messages to it
14+
$mail_box = setup_test_mailbox('bug80438', 10);
15+
16+
// Delete messages to remove the numerical ordering
17+
imap_delete($mail_box, 5);
18+
imap_delete($mail_box, 6);
19+
imap_delete($mail_box, 7);
20+
imap_delete($mail_box, 8);
21+
imap_expunge($mail_box);
22+
23+
$message_number_array = imap_search($mail_box, 'ALL', SE_UID);
24+
25+
var_dump($message_number_array);
26+
27+
foreach ($message_number_array as $message_unique_id)
28+
{
29+
echo 'Unique ID: ';
30+
var_dump($message_unique_id);
31+
echo 'Ordered message number: ';
32+
var_dump(imap_msgno($mail_box, $message_unique_id));
33+
}
34+
35+
imap_close($mail_box);
36+
37+
?>
38+
--CLEAN--
39+
<?php
40+
$mailbox_suffix = 'bug80438';
41+
require_once __DIR__.'/setup/clean.inc';
42+
?>
43+
--EXPECT--
44+
*** Testing imap_fetch_overview() : basic functionality ***
45+
Create a temporary mailbox and add 10 msgs
46+
New mailbox created
47+
array(6) {
48+
[0]=>
49+
int(1)
50+
[1]=>
51+
int(2)
52+
[2]=>
53+
int(3)
54+
[3]=>
55+
int(4)
56+
[4]=>
57+
int(9)
58+
[5]=>
59+
int(10)
60+
}
61+
Unique ID: int(1)
62+
Ordered message number: int(1)
63+
Unique ID: int(2)
64+
Ordered message number: int(2)
65+
Unique ID: int(3)
66+
Ordered message number: int(3)
67+
Unique ID: int(4)
68+
Ordered message number: int(4)
69+
Unique ID: int(9)
70+
Ordered message number: int(5)
71+
Unique ID: int(10)
72+
Ordered message number: int(6)

0 commit comments

Comments
 (0)