FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=16148&edit=1

ID: 16148
Updated by: tacker@php.net
Reported By: alexiev at gmail dot com
Summary: Wrong int presentation in encode
-Status: Open
+Status: Verified
Type: Bug
Package: File_Bittorrent2
Operating System: Ubuntu intrepid
Package Version: 1.3.0
PHP Version: Irrelevant
-Assigned To:
+Assigned To: tacker
Roadmap Versions:
New Comment:

-Status: Open
+Status: Verified
-Assigned To:
+Assigned To: tacker




Previous Comments:
------------------------------------------------------------------------

[2009-04-24 12:38:03] sash

Description:
------------
File_Bittorrent2_Encode::encode uses round() for integers.
round(1400000) returns 1.4E+6 which is invalid in bencode!

Try changing the line
return $this->encode_int(round($mixed));
to
return $this->encode_int(sprintf('%d', round($mixed)));

Test script:
---------------
$e = new File_Bittorrent2_Encode();
echo $e->encode(1400000);

Expected result:
----------------
i1400000e

Actual result:
--------------
i1.4E+6e

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

Search Discussions

  • Tacker at Apr 24, 2009 at 10:54 am
    Edit report at http://pear.php.net/bugs/bug.php?id=16148&edit=1

    ID: 16148
    Updated by: tacker@php.net
    Reported By: alexiev at gmail dot com
    Summary: Wrong int presentation in encode
    Status: Verified
    Type: Bug
    Package: File_Bittorrent2
    Operating System: Ubuntu intrepid
    Package Version: 1.3.0
    PHP Version: Irrelevant
    Assigned To: tacker
    -Roadmap Versions:
    +Roadmap Versions: 1.3.1
    New Comment:

    -Roadmap Versions:
    +Roadmap Versions: 1.3.1




    Previous Comments:
    ------------------------------------------------------------------------

    [2009-04-24 12:52:45] tacker

    -Status: Open
    +Status: Verified
    -Assigned To:
    +Assigned To: tacker


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

    [2009-04-24 12:38:03] sash

    Description:
    ------------
    File_Bittorrent2_Encode::encode uses round() for integers.
    round(1400000) returns 1.4E+6 which is invalid in bencode!

    Try changing the line
    return $this->encode_int(round($mixed));
    to
    return $this->encode_int(sprintf('%d', round($mixed)));

    Test script:
    ---------------
    $e = new File_Bittorrent2_Encode();
    echo $e->encode(1400000);

    Expected result:
    ----------------
    i1400000e

    Actual result:
    --------------
    i1.4E+6e

    ------------------------------------------------------------------------
  • Alexiev at Apr 24, 2009 at 3:56 pm
    Edit report at http://pear.php.net/bugs/bug.php?id=16148&edit=1

    ID: 16148
    Comment by: alexiev@gmail.com
    Reported By: alexiev at gmail dot com
    Summary: Wrong int presentation in encode
    Status: Verified
    Type: Bug
    Package: File_Bittorrent2
    Operating System: Ubuntu intrepid
    Package Version: 1.3.0
    PHP Version: Irrelevant
    Assigned To: tacker
    Roadmap Versions:
    New Comment:

    More like "return $this->encode_int(sprintf('%.0f', round($mixed)));"
    so larger numbers can also be encoded correctly


    Previous Comments:
    ------------------------------------------------------------------------

    [2009-04-24 12:53:48] tacker

    -Roadmap Versions:
    +Roadmap Versions: 1.3.1


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

    [2009-04-24 12:52:45] tacker

    -Status: Open
    +Status: Verified
    -Assigned To:
    +Assigned To: tacker


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

    [2009-04-24 12:38:03] sash

    Description:
    ------------
    File_Bittorrent2_Encode::encode uses round() for integers.
    round(1400000) returns 1.4E+6 which is invalid in bencode!

    Try changing the line
    return $this->encode_int(round($mixed));
    to
    return $this->encode_int(sprintf('%d', round($mixed)));

    Test script:
    ---------------
    $e = new File_Bittorrent2_Encode();
    echo $e->encode(1400000);

    Expected result:
    ----------------
    i1400000e

    Actual result:
    --------------
    i1.4E+6e

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedApr 24, '09 at 10:52a
activeApr 24, '09 at 3:56p
posts3
users2
websitepear.php.net

2 users in discussion

Tacker: 2 posts Alexiev: 1 post

People

Translate

site design / logo © 2022 Grokbase