Skip to content

Commit 9b2a3c1

Browse files
committed
Fix stubs for bzerr* functions
These can return false if the stream is not a bz2 stream. Also emit a warning in this case, this should not be failing silently.
1 parent b302bfa commit 9b2a3c1

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

ext/bz2/bz2.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ static void php_bz2_error(INTERNAL_FUNCTION_PARAMETERS, int opt)
578578
php_stream_from_zval(stream, bzp);
579579

580580
if (!php_stream_is(stream, PHP_STREAM_IS_BZIP2)) {
581+
php_error_docref(NULL, E_WARNING, "Stream is not a bz2 stream");
581582
RETURN_FALSE;
582583
}
583584

ext/bz2/bz2.stub.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ function bzflush($bz): bool {}
3030
function bzclose($bz): bool {}
3131

3232
/** @param resource $bz */
33-
function bzerrno($bz): int {}
33+
function bzerrno($bz): int|false {}
3434

3535
/** @param resource $bz */
36-
function bzerrstr($bz): string {}
36+
function bzerrstr($bz): string|false {}
3737

3838
/** @param resource $bz */
39-
function bzerror($bz): array {}
39+
function bzerror($bz): array|false {}
4040

4141
function bzcompress(string $data, int $block_size = 4, int $work_factor = 0): string|int {}
4242

ext/bz2/bz2_arginfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 0cd7792480671883ebae30ae8358b8f8e3390474 */
2+
* Stub hash: 67689133cbaffce7c139578f5070ecfc8ab6ec55 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_bzopen, 0, 0, 2)
55
ZEND_ARG_INFO(0, file)
@@ -23,15 +23,15 @@ ZEND_END_ARG_INFO()
2323

2424
#define arginfo_bzclose arginfo_bzflush
2525

26-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bzerrno, 0, 1, IS_LONG, 0)
26+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_bzerrno, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
2727
ZEND_ARG_INFO(0, bz)
2828
ZEND_END_ARG_INFO()
2929

30-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bzerrstr, 0, 1, IS_STRING, 0)
30+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_bzerrstr, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
3131
ZEND_ARG_INFO(0, bz)
3232
ZEND_END_ARG_INFO()
3333

34-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bzerror, 0, 1, IS_ARRAY, 0)
34+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_bzerror, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
3535
ZEND_ARG_INFO(0, bz)
3636
ZEND_END_ARG_INFO()
3737

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Calling bzerr* functions on non-bz2 streams
3+
--SKIPIF--
4+
<?php if (!extension_loaded("bz2")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$f = fopen(__FILE__, 'r');
8+
var_dump(bzerrno($f));
9+
var_dump(bzerrstr($f));
10+
var_dump(bzerror($f));
11+
?>
12+
--EXPECTF--
13+
Warning: bzerrno(): Stream is not a bz2 stream in %s on line %d
14+
bool(false)
15+
16+
Warning: bzerrstr(): Stream is not a bz2 stream in %s on line %d
17+
bool(false)
18+
19+
Warning: bzerror(): Stream is not a bz2 stream in %s on line %d
20+
bool(false)

0 commit comments

Comments
 (0)