Skip to content
Closed

Gh18976 #18977

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/standard/pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ PHP_FUNCTION(pack)
switch ((int) code) {
case 'h':
case 'H':
INC_OUTPUTPOS((arg + (arg % 2)) / 2,1) /* 4 bit per arg */
INC_OUTPUTPOS((arg / 2) + (arg % 2),1) /* 4 bit per arg */
break;

case 'a':
Expand Down
14 changes: 14 additions & 0 deletions ext/standard/tests/strings/gh18976.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
GH-18976 (pack overflow with h/H format)
--INI--
memory_limit=-1
--FILE--
<?php
pack('h2147483647', 1);
pack('H2147483647', 1);
?>
--EXPECTF--

Warning: pack(): Type h: not enough characters in string in %s on line %d

Warning: pack(): Type H: not enough characters in string in %s on line %d
Loading