Debian Bug report logs - #698109
PHP5 integer error in json_decode()

version graph

Package: php5; Maintainer for php5 is (unknown);

Reported by: Pigeon <pigeon@pigeonsnest.co.uk>

Date: Mon, 14 Jan 2013 07:33:04 UTC

Severity: normal

Found in version php5/5.2.6.dfsg.1-1+lenny9

Fixed in version 5.3.3-7+squeeze14

Done: Ondřej Surý <ondrej@debian.org>

Bug is archived. No further changes may be made.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>:
Bug#698109; Package php5. (Mon, 14 Jan 2013 07:33:07 GMT) (full text, mbox, link).


Acknowledgement sent to Pigeon <pigeon@pigeonsnest.co.uk>:
New Bug report received and forwarded. Copy sent to Debian PHP Maintainers <pkg-php-maint@lists.alioth.debian.org>. (Mon, 14 Jan 2013 07:33:07 GMT) (full text, mbox, link).


Message #5 received at submit@bugs.debian.org (full text, mbox, reply):

From: Pigeon <pigeon@pigeonsnest.co.uk>
To: submit@bugs.debian.org
Subject: PHP5 integer error in json_decode()
Date: Mon, 14 Jan 2013 06:59:12 +0000
[Message part 1 (text/plain, inline)]
Package: php5
Version: 5.2.6.dfsg.1-1+lenny9

I realise this is an old version, but on looking through the bug
reports and changelogs I see no mention of any similar bugs or actions
to fix them, so I consider it possible that the bug still exists.

json_decode() does not always correctly decode integer values on large
integers such as twitter status IDs. It subtracts 1, or sometimes 2,
from the decoded value. This does not always happen and appears to be
unpredictable.

This is not an overflow error as the integers concerned, though large,
are still below the limit for the 64-bit system on which I discovered
the bug.

Here are some examples of incorrect output, generated using
command-line PHP with sample truncated twitter JSON strings:

Subtracting 1:

<?php
$j='[{"created_at":"Mon Jan 14 01:01:28 +0000 2013","id":190624640131428353,"id_str":"190624640131428353"}]';
$a=190624640131428353;
$b='190624640131428353';
$c=intval($a);
$d=json_decode($j, true);
$e=json_decode($j, false);
var_dump($a);
var_dump($b);
var_dump($c);
var_dump($d);
var_dump($e);
?>
int(190624640131428353)
string(18) "190624640131428353"
int(190624640131428353)
array(1) {
  [0]=>
  array(3) {
    ["created_at"]=>
    string(30) "Mon Jan 14 01:01:28 +0000 2013"
    ["id"]=>
    int(190624640131428352)
    ["id_str"]=>
    string(18) "190624640131428353"
  }
}
array(1) {
  [0]=>
  object(stdClass)#1 (3) {
    ["created_at"]=>
    string(30) "Mon Jan 14 01:01:28 +0000 2013"
    ["id"]=>
    int(190624640131428352)
    ["id_str"]=>
    string(18) "190624640131428353"
  }
}


Subtracting 2:

<?php
$j='[{"created_at":"Mon Jan 14 01:01:28 +0000 2013","id":190624590269513730,"id_str":"190624590269513730"}]';
$a=190624590269513730;
$b='190624590269513730';
$c=intval($a);
$d=json_decode($j, true);
$e=json_decode($j, false);
var_dump($a);
var_dump($b);
var_dump($c);
var_dump($d);
var_dump($e);
?>
int(190624590269513730)
string(18) "190624590269513730"
int(190624590269513730)
array(1) {
  [0]=>
  array(3) {
    ["created_at"]=>
    string(30) "Mon Jan 14 01:01:28 +0000 2013"
    ["id"]=>
    int(190624590269513728)
    ["id_str"]=>
    string(18) "190624590269513730"
  }
}
array(1) {
  [0]=>
  object(stdClass)#1 (3) {
    ["created_at"]=>
    string(30) "Mon Jan 14 01:01:28 +0000 2013"
    ["id"]=>
    int(190624590269513728)
    ["id_str"]=>
    string(18) "190624590269513730"
  }
}
						
By comparison, the (larger) integer 190694799109677056 is handled correctly.

-- 
Pigeon

Be kind to pigeons        - -        Pigeon's Nest: http://pigeonsnest.co.uk/
                          - -      Lucy Pinder TV: http://www.lucy-pinder.tv/
GPG key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x21C61F7F
[signature.asc (application/pgp-signature, inline)]

Reply sent to Ondřej Surý <ondrej@debian.org>:
You have taken responsibility. (Mon, 14 Jan 2013 08:42:06 GMT) (full text, mbox, link).


Notification sent to Pigeon <pigeon@pigeonsnest.co.uk>:
Bug acknowledged by developer. (Mon, 14 Jan 2013 08:42:07 GMT) (full text, mbox, link).


Message #10 received at 698109-done@bugs.debian.org (full text, mbox, reply):

From: Ondřej Surý <ondrej@debian.org>
To: Pigeon <pigeon@pigeonsnest.co.uk>, 698109-done@bugs.debian.org
Subject: Re: [php-maint] Bug#698109: PHP5 integer error in json_decode()
Date: Mon, 14 Jan 2013 09:40:00 +0100
Version: 5.3.3-7+squeeze14

Hi Pigeon,

this bug don't manifest in squeeze, thus marking it as fixed.  It
works correctly on 64-bit. On 32-bit, it converts the number to float
to prevent the overfloat.

Ondrej

On Mon, Jan 14, 2013 at 7:59 AM, Pigeon <pigeon@pigeonsnest.co.uk> wrote:
> Package: php5
> Version: 5.2.6.dfsg.1-1+lenny9
>
> I realise this is an old version, but on looking through the bug
> reports and changelogs I see no mention of any similar bugs or actions
> to fix them, so I consider it possible that the bug still exists.
>
> json_decode() does not always correctly decode integer values on large
> integers such as twitter status IDs. It subtracts 1, or sometimes 2,
> from the decoded value. This does not always happen and appears to be
> unpredictable.
>
> This is not an overflow error as the integers concerned, though large,
> are still below the limit for the 64-bit system on which I discovered
> the bug.
>
> Here are some examples of incorrect output, generated using
> command-line PHP with sample truncated twitter JSON strings:
>
> Subtracting 1:
>
> <?php
> $j='[{"created_at":"Mon Jan 14 01:01:28 +0000 2013","id":190624640131428353,"id_str":"190624640131428353"}]';
> $a=190624640131428353;
> $b='190624640131428353';
> $c=intval($a);
> $d=json_decode($j, true);
> $e=json_decode($j, false);
> var_dump($a);
> var_dump($b);
> var_dump($c);
> var_dump($d);
> var_dump($e);
> ?>
> int(190624640131428353)
> string(18) "190624640131428353"
> int(190624640131428353)
> array(1) {
>   [0]=>
>   array(3) {
>     ["created_at"]=>
>     string(30) "Mon Jan 14 01:01:28 +0000 2013"
>     ["id"]=>
>     int(190624640131428352)
>     ["id_str"]=>
>     string(18) "190624640131428353"
>   }
> }
> array(1) {
>   [0]=>
>   object(stdClass)#1 (3) {
>     ["created_at"]=>
>     string(30) "Mon Jan 14 01:01:28 +0000 2013"
>     ["id"]=>
>     int(190624640131428352)
>     ["id_str"]=>
>     string(18) "190624640131428353"
>   }
> }
>
>
> Subtracting 2:
>
> <?php
> $j='[{"created_at":"Mon Jan 14 01:01:28 +0000 2013","id":190624590269513730,"id_str":"190624590269513730"}]';
> $a=190624590269513730;
> $b='190624590269513730';
> $c=intval($a);
> $d=json_decode($j, true);
> $e=json_decode($j, false);
> var_dump($a);
> var_dump($b);
> var_dump($c);
> var_dump($d);
> var_dump($e);
> ?>
> int(190624590269513730)
> string(18) "190624590269513730"
> int(190624590269513730)
> array(1) {
>   [0]=>
>   array(3) {
>     ["created_at"]=>
>     string(30) "Mon Jan 14 01:01:28 +0000 2013"
>     ["id"]=>
>     int(190624590269513728)
>     ["id_str"]=>
>     string(18) "190624590269513730"
>   }
> }
> array(1) {
>   [0]=>
>   object(stdClass)#1 (3) {
>     ["created_at"]=>
>     string(30) "Mon Jan 14 01:01:28 +0000 2013"
>     ["id"]=>
>     int(190624590269513728)
>     ["id_str"]=>
>     string(18) "190624590269513730"
>   }
> }
>
> By comparison, the (larger) integer 190694799109677056 is handled correctly.
>
> --
> Pigeon
>
> Be kind to pigeons        - -        Pigeon's Nest: http://pigeonsnest.co.uk/
>                           - -      Lucy Pinder TV: http://www.lucy-pinder.tv/
> GPG key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x21C61F7F
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFQ86y/UxADjyHGH38RAkgcAJ9d5t54rzyDQ79AwijhNsn9k+mXjACfaNMF
> msqBQWl0H/k8pd9WVChrYzY=
> =goVg
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> pkg-php-maint mailing list
> pkg-php-maint@lists.alioth.debian.org
> http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-php-maint



-- 
Ondřej Surý <ondrej@sury.org>



Bug archived. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Tue, 12 Feb 2013 07:25:50 GMT) (full text, mbox, link).


Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Sun Jul 2 03:47:24 2023; Machine Name: buxtehude

Debian Bug tracking system

Debbugs is free software and licensed under the terms of the GNU Public License version 2. The current version can be obtained from https://bugs.debian.org/debbugs-source/.

Copyright © 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson, 2005-2017 Don Armstrong, and many other contributors.