Uploaded image for project: 'CUBRID APIs'
  1. CUBRID APIs
  2. APIS-556

cubrid_fetch CUBRID_LOB tries to allocate 4 billion bytes

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: PHP 9.1.0 0004
    • Component/s: PHP Driver
    • Labels:
      None
    • Environment:

      CUBRID 9.1.0.0212

      Description

      I created a table with 2 entries using this code:

      {code}
      <?php
      // Table: test_lob (id INT, contents CLOB)

      $conn = cubrid_connect("localhost", 33000, "demodb", "public", "");

      cubrid_execute($conn,"DROP TABLE if exists test_lob");
      cubrid_execute($conn,"CREATE TABLE test_lob (id INT, contents CLOB)");

      $req = cubrid_prepare($conn, "INSERT INTO test_lob VALUES (?, ?)");

      cubrid_bind($req,1, 3);

      $lob = cubrid_lob2_new($conn, 'CLOB');
      cubrid_lob2_bind($req, 2, $lob);

      cubrid_execute($req);

      cubrid_bind($req, 1, 4);

      cubrid_lob2_bind($req, 2, 'CUBRID LOB2 TEST', 'CLOB');

      cubrid_execute($req);

      cubrid_disconnect($conn);
      ?>{code}

      Then, I ran this code:

      {code}
      <?php
      // Table: test_lob (id INT, contents CLOB)

      $conn = cubrid_connect("localhost", 33000, "demodb", "public", "");

      $req = cubrid_prepare($conn, "select * from test_lob where id=3");

      $row = cubrid_fetch($req, CUBRID_NUM | CUBRID_LOB);

      cubrid_lob2_export($row[1], "doc_1.txt");

      cubrid_lob2_close($row[1]);
      cubrid_disconnect($conn);
      ?>{code}

      This gives the error:

      {code}
      Fatal error: Out of memory (allocated 524288) (tried to allocate 4294967292 bytes) in C:\Users\user\Desktop\PHP Driver Tests\cubrid_lob2_export.php on line 8

      Call Stack:
      0.0005 331552 1. {main}() C:\Users\user\Desktop\PHP Driver Tests\cubrid_lob2_export.php:0
      0.0440 333208 2. cubrid_fetch() C:\Users\user\Desktop\PHP Driver Tests\cubrid_lob2_export.php:8{code}

      cubrid_fetch with CUBRID_LOB tries to allocate 4294967292 bytes. If I remove CUBRID_LOB from cubrid_fetch the error no longer occurs (but of course, the code won't be able to export the entry afterwards).

        Activity

        Hide
        cn15800 谢韦华[Bert] added a comment -

        Your example is not right,you should call cubrid_execute first when you call cubrid_fetch,and i found the document is wrong,
        I will fix the document http://www.php.net/manual/zh/function.cubrid-lob2-export.php
        :

        <?php
        // Table: test_lob (id INT, contents CLOB)

        $conn = cubrid_connect("localhost", 33000, "demodb", "dba", "");

        $req = cubrid_prepare($conn, "select * from test_lob where id=4");
        cubrid_execute($req);
        $row = cubrid_fetch($req, CUBRID_NUM | CUBRID_LOB);

        cubrid_lob2_export($row[1], "doc_1.txt");

        cubrid_lob2_close($row[1]);
        cubrid_disconnect($conn);
        ?>

        Show
        cn15800 谢韦华[Bert] added a comment - Your example is not right,you should call cubrid_execute first when you call cubrid_fetch,and i found the document is wrong, I will fix the document http://www.php.net/manual/zh/function.cubrid-lob2-export.php : <?php // Table: test_lob (id INT, contents CLOB) $conn = cubrid_connect("localhost", 33000, "demodb", "dba", ""); $req = cubrid_prepare($conn, "select * from test_lob where id=4"); cubrid_execute($req); $row = cubrid_fetch($req, CUBRID_NUM | CUBRID_LOB); cubrid_lob2_export($row [1] , "doc_1.txt"); cubrid_lob2_close($row [1] ); cubrid_disconnect($conn); ?>
        Hide
        ryin005 Ray Yin added a comment -

        There is still an error in the document http://www.php.net/manual/zh/function.cubrid-lob2-export.php

        Example #1 cubrid_lob2_export() example

        {code}
        $req = cubrid_prepare($conn, "select * from test_lob");{code}

        should be

        {code}
        $req = cubrid_prepare($conn, "select * from doc");{code}

        Reopen the issue

        Show
        ryin005 Ray Yin added a comment - There is still an error in the document http://www.php.net/manual/zh/function.cubrid-lob2-export.php Example #1 cubrid_lob2_export() example {code} $req = cubrid_prepare($conn, "select * from test_lob");{code} should be {code} $req = cubrid_prepare($conn, "select * from doc");{code} Reopen the issue
        Hide
        cn15800 谢韦华[Bert] added a comment -

        fixed

        Show
        cn15800 谢韦华[Bert] added a comment - fixed
        Hide
        ryin005 Ray Yin added a comment -

        The document has been updated.

        The issue could be closed

        Show
        ryin005 Ray Yin added a comment - The document has been updated. The issue could be closed

          People

          • Assignee:
            cn15800 谢韦华[Bert]
            Reporter:
            ovidiu.veliscu Veliscu Ovidiu
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: