Skip to content

Commit ac495bf

Browse files
committed
boundary check while parsing bint to avoid segfault
1 parent 7c55fb1 commit ac495bf

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/bint.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ zval bint::parse(const std::string &ben, size_t &pt)
3333
if (ben[pt] != 'i')
3434
return bitem::throw_general_exception("Error parsing bint");
3535
size_t start = ++pt;
36-
while (ben[pt] != 'e')
36+
while (pt < ben.length() && ben[pt] != 'e')
3737
++pt;
3838
long result = std::stoll(ben.substr(start, pt - start));
3939
++pt;

tests/non_ending_int.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
PHP Bencode - Non-Ending Integer Test
3+
--FILE--
4+
<?php
5+
error_reporting(E_ALL);
6+
7+
$bstr = bitem::parse('i10');
8+
echo $bstr;
9+
10+
exit(0);
11+
?>
12+
--EXPECTF--
13+
i10e

0 commit comments

Comments
 (0)