php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19474 $_POST values are truncated
Submitted: 2002-09-18 05:52 UTC Modified: 2002-09-20 07:49 UTC
From: php-jp at typhoon dot jp Assigned:
Status: Closed Package: mbstring related
PHP Version: 4.2.3 OS: FreeBSD 4.X
Private report: No CVE-ID: None
 [2002-09-18 05:52 UTC] php-jp at typhoon dot jp
When checkboxes are used in a form with arrays (e.g. name=something[]) values retrieved from the resulting $_POST[something] array are trunacted.  In fact, the first 4 bytes are truncated.  

If values are POSTED one by one, i.e. not via an array, things seem to work.

The same script used to work on 4.2.2.  I discovered this problem after upgrading to 4.2.3

---sample form starts---
<html>
<head>
</head>
<form action="prob1.php" method="POST">
<input type=checkbox name=somevar[] value="01234567890abcdefghijklmnopqrstu">
01234567890abcdefghijklmnopqrstu<br>
<input type=checkbox name=somevar[] value="abcdefghijklmnopqrstu">abcdefghijklmnopqrstu<br>
<input type=checkbox name=somevar[] value="01234567">01234567<br>
<input type=checkbox name=somevar[] value="0123456">0123456<br>
<input type=checkbox name=somevar[] value="012345">012345<br>
<input type=checkbox name=somevar[] value="01234">01234<br>
<input type=checkbox name=somevar[] value="0123">0123<br>
<input type=checkbox name=somevar[] value="012">012<br>
<input type=checkbox name=somevar[] value="01">01<br>
<input type=checkbox name=somevar[] value="0">0<br>
<input type="submit" value="OK">
</body>
</html>
---sample form ends---

---PHP used to process above starts---
<html>
<head>
</head>
<?
$somevar_arr = $_POST["somevar"];
if( sizeof( $somevar_arr ) ) {
  for( $i = 0; $i < count( $somevar_arr ); $i++ ) {
    printf("somevar[%d]: %s <br>", $i, $somevar_arr[$i] );
  }
}
for( $i = 0; $i < count( $_ENV ); $i++ ) {
  printf("env[%d]: %s <br>", $i, $ENV[$i] );
}

?>
<hr>
</body>
</html>

---scripts ends ---

Results generated by script:

somevar[0]: 4567890abcdefghijklmnopqrstu 
somevar[1]: efghijklmnopqrstu 
somevar[2]: 4567 
somevar[3]: 456 
somevar[4]: 45 
somevar[5]: 4 
somevar[6]: 
somevar[7]: 012 
somevar[8]: 01 
somevar[9]: 0 

-------------------------

===end of report===

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-18 05:55 UTC] derick@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.

Already fixed, recompile --without-mb-str-enc (or simlilar) to make this go away with 4.2.3.

Derick
 [2002-09-20 06:05 UTC] chad at stather dot net
This bug is not restricted to checkbox's! I think it applies to all input types.. The following example is a modification of the first test script but using text inputs. I asked my ISP to apply the recommended recompile config but it didn't work! PLEASE HELP

---sample form starts---

<html>
<head>
</head>
<form action="phptest.php" method="POST">
0 <input type=text name=somevar[] value="01234567890abcdefghijklmnopqrstu">01234567890abcdefghijklmnopqrstu<br>
1 <input type=text checked name=somevar[] value="abcdefghijklmnopqrstu">abcdefghijklmnopqrstu<br>
2 <input type=text checked name=somevar[] value="01234567">01234567<br>
3 <input type=text checked name=somevar[] value="0123456">0123456<br>
4 <input type=text checked name=somevar[] value="012345">012345<br>
5 <input type=text checked name=somevar[] value="01234">01234<br>
6 <input type=text checked name=somevar[] value="0123">0123<br>
7 <input type=text checked name=somevar[] value="012">012<br>
8 <input type=text checked name=somevar[] value="01">01<br>
9 <input type=text checked name=somevar[] value="0">0<br>
10 Text <input type=text name=somevar[] value="ABCDEFGHI"><br>
<input type="submit" value="OK">

<hr>
<P>
<?
$somevar_arr = $_POST["somevar"];
if( sizeof( $somevar_arr ) ) {
  for( $i = 0; $i < count( $somevar_arr ); $i++ ) {
    printf("somevar[%d]: %s <br>", $i, $somevar_arr[$i] );
  }
}

for( $i = 0; $i < count( $_ENV ); $i++ ) {
  if ($ENV[$i]) {
  printf("env[%d]: %s <br>", $i, $ENV[$i] );
  }
}

?>


</body>
</html>

---scripts ends ---

Results generated by script:

somevar[0]: 4567890abcdefghijklmnopqrstu 
somevar[1]: efghijklmnopqrstu 
somevar[2]: 4567 
somevar[3]: 456 
somevar[4]: 45 
somevar[5]: 4 
somevar[6]: 
somevar[7]: 012 
somevar[8]: 01 
somevar[9]: 0 
somevar[10]: EFGHI 

-------------------------
 [2002-09-20 06:17 UTC] php-jp at typhoon dot jp
Are you using the "mb" extension? i.e. did you compile it to enable multi-byte support?  If so, you (or your ISP) need to get the latest "mbstring.c" file from the CVS and recompile and reinstall.  The problem lies in mbstring.c and it has been fixed by its author.
---ends---
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Dec 09 14:03:33 2021 UTC