Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding vector of RAW causes core dump #13

Closed
kornefalk opened this issue Sep 7, 2015 · 2 comments
Closed

Binding vector of RAW causes core dump #13

kornefalk opened this issue Sep 7, 2015 · 2 comments
Assignees

Comments

@kornefalk
Copy link

Program received signal SIGSEGV, Segmentation fault.

0x00007ffff7ddb559 in OCI_BindCheck () from /vobs/thirdparty/ocilib/installed/linux/lib/libocilib.so
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.132.el6.x86_64 libaio-0.3.107-10.el6.x86_64 libgcc-4.4.7-4.el6.x86_64
(gdb) where
#0  0x00007ffff7ddb559 in OCI_BindCheck () from /vobs/thirdparty/ocilib/installed/linux/lib/libocilib.so
#1  0x00007ffff7dde544 in OCI_ExecuteInternal () from /vobs/thirdparty/ocilib/installed/linux/lib/libocilib.so
#2  0x00007ffff7ddec58 in OCI_Execute () from /vobs/thirdparty/ocilib/installed/linux/lib/libocilib.so
#3  0x00000000004087d2 in ocilib::Statement::ExecutePrepared() () at /vobs/thirdparty/ocilib/installed/include/ocilib_impl.hpp:4518
#4  0x00000000004057a2 in main () at BigRaw.cpp:113
(gdb) info locals 
No symbol table info available.
(gdb) up
#1  0x00007ffff7dde544 in OCI_ExecuteInternal () from /vobs/thirdparty/ocilib/installed/linux/lib/libocilib.so
(gdb) info locals 
No symbol table info available.
(gdb) up
#2  0x00007ffff7ddec58 in OCI_Execute () from /vobs/thirdparty/ocilib/installed/linux/lib/libocilib.so
(gdb) info locals 
No symbol table info available.
(gdb) up
#3  0x00000000004087d2 in ocilib::Statement::ExecutePrepared() () at /vobs/thirdparty/ocilib/installed/include/ocilib_impl.hpp:4518
4518        Check(OCI_Execute(*this));
(gdb) info locals 
length_multiplier = 50
std::__ioinit = {static _S_refcount = 2, static _S_synced_with_stdio = true}

Test program

#include <iostream>
#include <iomanip>
#include <string>
#include <time.h>
#include <sstream>
#include <vector>

#include "ocilib.hpp"

using namespace ocilib;
using namespace std;

const int length_multiplier = 50; // 2

ostring v2s(const Raw & r)
{
   ostringstream ss;
   ss << "vector length=" << r.size() << endl;
   ss << setfill('0') << hex;
   int pos=0;
   for (auto v : r)
   {
      ss << setw(2) << (int)v;
      if (((++pos) % 16) == 15)
      {
     if ((pos % 64) == 63)
        ss << endl;
     else
        ss << ' ';
      }
   }
   ss << endl;
   return ss.str();
}

void setstmt(Statement & stmt, const ostring & line)
{
   stmt.Prepare(line);
}

ostring getCrateStmt()
{
   return "CREATE TABLE TEST_BIG (n NUMBER, v RAW(2000) )";
}

ostring getDropStmt()
{
   return "DROP TABLE TEST_BIG";
}

ostring getstmt()
{
   return "INSERT INTO TEST_BIG ( n, v) values ( :1, :2)";
}

unsigned char avalue(int x)
{
   return static_cast<unsigned char>((x + 132) % 256);
}

int main(int argc, char**argv)
{
   if (argc < 4)
   {
      cout << "user pwd dbcon" << endl;
      return 1;
   }
   try
   {
      Environment::Initialize();

      Connection con(argv[3], argv[1], argv[2]);
      try {
     Statement sc(con);
     sc.Prepare(getDropStmt());
     sc.ExecutePrepared();
      }
      catch (Exception & ex)
      {
     cout << "Ignored: " << ex.what() << endl;
      }
      {
     Statement sc(con);
     sc.Prepare(getCrateStmt());
     sc.ExecutePrepared();
      }

      {
     Statement st(con);
     st.Prepare(getstmt());
     vector<Raw> rvalues;
     vector<int> nvalues;
     for (int i=1; i<=10; i++)
     {
        nvalues.push_back(i);
        Raw v;
        int length=250+i*length_multiplier;
        cout << setw(2) << i << " length=" << length << endl;
        v.resize(length);
        for (int pos=0; pos<length; ++pos)
           v[pos] = avalue(pos);
        cout << "Store RAW:" << v2s(v) << endl;
        rvalues.push_back(v);
     }
     st.SetBindArraySize(static_cast<unsigned int>(rvalues.size()));
     cout << "Try to bind " << rvalues.size() << " values..." << endl;
     st.Bind(":1", nvalues, BindInfo::InOut);
     unsigned int maxsize=2000U;
     st.Bind<ocilib::Raw, unsigned int>(":2",
                        rvalues,
                        maxsize,
                        ocilib::BindInfo::InOut);
     st.ExecutePrepared();

     cout << "inserted 10 rows, affected rows= " << st.GetAffectedRows() << endl;

     con.Commit();
      }
      {
     Statement stmt(con);
     stmt.Execute("SELECT n, v from TEST_BIG");
     Resultset rs = stmt.GetResultset();
     while (rs++)
     {
        int n = rs.Get<int>(1);
        Raw v = rs.Get<Raw>(2);
        cout << setw(2) << n << " value length=" << v.size() << "   ";
        bool ok=true;
        int fail_pos=0;
        int length=250+n*length_multiplier;
        for (int pos=0; pos<length; ++pos)
        {
           if (v[pos] != avalue(pos))
           {
          ok = false;
          fail_pos=pos;
          break;
           }
        }
        if (ok)
        {
           cout << "ok" << endl;
        } else {
           cout << "failed at pos " << fail_pos
             << " expected " << hex << (int)static_cast<unsigned char>((fail_pos % 256) ^ 0xAA)
             << " got " << (int)v[fail_pos] << dec
             << v2s(v)
             << endl;
        }
     }
      }
   }
   catch (Exception & ex)
   {
      cerr << "OciLib::Exception" << endl;
      cerr << "Message     : " << ex.GetMessage() << endl;
      cerr << "Oracle error: " << ex.GetOracleErrorCode() << endl;
      cerr << "what        : " << ex.what() << endl;
      cerr << "Internal err: " << ex.GetInternalErrorCode() << endl;
   }
   catch (exception &ex)
   {
      cerr << "EXCEPTION:" << endl;
      cerr << ex.what() << endl;
   }

   Environment::Cleanup();

   return EXIT_SUCCESS;
}

Valgrind adds more information (line numbers differs from the the original source after adding some diagnostic lines)

==4880== Invalid write of size 1
==4880==    at 0x4A08CE8: memcpy (mc_replace_strmem.c:882)
==4880==    by 0x408054: ocilib::BindArray::BindArrayObject<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned char>::SetInData() (ocilib_impl.hpp:4180)
==4880==    by 0x407F3A: ocilib::BindArray::SetInData() (ocilib_impl.hpp:4085)
==4880==    by 0x408597: ocilib::BindsHolder::SetInData() (ocilib_impl.hpp:4395)
==4880==    by 0x408B67: ocilib::Statement::SetInData() (ocilib_impl.hpp:5394)
==4880==    by 0x4087BD: ocilib::Statement::ExecutePrepared() (ocilib_impl.hpp:4517)
==4880==    by 0x4057A1: main (BigRaw.cpp:113)
==4880==  Address 0x833884b is 5 bytes before a block of size 28 alloc'd
==4880==    at 0x4A069EE: malloc (vg_replace_malloc.c:270)
==4880==    by 0x4C4AB8C: OCI_MemAlloc (memory.c:70)
==4880==    by 0x4C5E23B: OCI_BindData (statement.c:805)
==4880==    by 0x4C631E7: OCI_BindArrayOfRaws (statement.c:2948)
==4880==    by 0x408A3A: void ocilib::Statement::Bind<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned int>(std::string const&, std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&, unsigned int, ocilib::Enum<ocilib::BindInfo::BindDirectionValues>) (ocilib_impl.hpp:5103)
==4880==    by 0x40577A: main (BigRaw.cpp:112)
==4880== 
==4880== Invalid write of size 8
==4880==    at 0x4A08D13: memcpy (mc_replace_strmem.c:882)
==4880==    by 0x408054: ocilib::BindArray::BindArrayObject<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned char>::SetInData() (ocilib_impl.hpp:4180)
==4880==    by 0x407F3A: ocilib::BindArray::SetInData() (ocilib_impl.hpp:4085)
==4880==    by 0x408597: ocilib::BindsHolder::SetInData() (ocilib_impl.hpp:4395)
==4880==    by 0x408B67: ocilib::Statement::SetInData() (ocilib_impl.hpp:5394)
==4880==    by 0x4087BD: ocilib::Statement::ExecutePrepared() (ocilib_impl.hpp:4517)
==4880==    by 0x4057A1: main (BigRaw.cpp:113)
==4880==  Address 0x8338840 is 16 bytes before a block of size 28 alloc'd
==4880==    at 0x4A069EE: malloc (vg_replace_malloc.c:270)
==4880==    by 0x4C4AB8C: OCI_MemAlloc (memory.c:70)
==4880==    by 0x4C5E23B: OCI_BindData (statement.c:805)
==4880==    by 0x4C631E7: OCI_BindArrayOfRaws (statement.c:2948)
==4880==    by 0x408A3A: void ocilib::Statement::Bind<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned int>(std::string const&, std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&, unsigned int, ocilib::Enum<ocilib::BindInfo::BindDirectionValues>) (ocilib_impl.hpp:5103)
==4880==    by 0x40577A: main (BigRaw.cpp:112)
==4880== 
==4880== Invalid write of size 1
==4880==    at 0x4A08DAF: memcpy (mc_replace_strmem.c:882)
==4880==    by 0x408054: ocilib::BindArray::BindArrayObject<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned char>::SetInData() (ocilib_impl.hpp:4180)
==4880==    by 0x407F3A: ocilib::BindArray::SetInData() (ocilib_impl.hpp:4085)
==4880==    by 0x408597: ocilib::BindsHolder::SetInData() (ocilib_impl.hpp:4395)
==4880==    by 0x408B67: ocilib::Statement::SetInData() (ocilib_impl.hpp:5394)
==4880==    by 0x4087BD: ocilib::Statement::ExecutePrepared() (ocilib_impl.hpp:4517)
==4880==    by 0x4057A1: main (BigRaw.cpp:113)
==4880==  Address 0x833904e is not stack'd, malloc'd or (recently) free'd
==4880== 
==4880== Invalid write of size 2
==4880==    at 0x4A08D74: memcpy (mc_replace_strmem.c:882)
==4880==    by 0x408054: ocilib::BindArray::BindArrayObject<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned char>::SetInData() (ocilib_impl.hpp:4180)
==4880==    by 0x407F3A: ocilib::BindArray::SetInData() (ocilib_impl.hpp:4085)
==4880==    by 0x408597: ocilib::BindsHolder::SetInData() (ocilib_impl.hpp:4395)
==4880==    by 0x408B67: ocilib::Statement::SetInData() (ocilib_impl.hpp:5394)
==4880==    by 0x4087BD: ocilib::Statement::ExecutePrepared() (ocilib_impl.hpp:4517)
==4880==    by 0x4057A1: main (BigRaw.cpp:113)
==4880==  Address 0x8339850 is not stack'd, malloc'd or (recently) free'd
==4880== 
==4880== Invalid read of size 8
==4880==    at 0x5BE37B0: __intel_new_memcpy (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6C60900: ttcacs (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6C2F5F4: ttcdrv (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BDD9B8: nioqwa (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BB95C6: upirtrc (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BC5155: kpurcsc (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BBE56B: kpuexec (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BBA06A: OCIStmtExecute (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x4C605DA: OCI_ExecuteInternal (statement.c:1923)
==4880==    by 0x4C60C57: OCI_Execute (statement.c:2149)
==4880==    by 0x4087D1: ocilib::Statement::ExecutePrepared() (ocilib_impl.hpp:4518)
==4880==    by 0x4057A1: main (BigRaw.cpp:113)
==4880==  Address 0x8338724 is 4 bytes inside a block of size 10 alloc'd
==4880==    at 0x4A07152: operator new[](unsigned long) (vg_replace_malloc.c:363)
==4880==    by 0x40E924: ocilib::BindArray::BindArrayObject<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned char>::AllocData() (ocilib_impl.hpp:4109)
==4880==    by 0x40C17B: ocilib::BindArray::BindArrayObject<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned char>::BindArrayObject(ocilib::Statement const&, std::string const&, std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&, unsigned int, unsigned int) (ocilib_impl.hpp:4097)
==4880==    by 0x40A410: void ocilib::BindArray::SetVector<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned char>(std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&, unsigned int, unsigned int) (ocilib_impl.hpp:4069)
==4880==    by 0x4089F7: void ocilib::Statement::Bind<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned int>(std::string const&, std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&, unsigned int, ocilib::Enum<ocilib::BindInfo::BindDirectionValues>) (ocilib_impl.hpp:5101)
==4880==    by 0x40577A: main (BigRaw.cpp:112)
==4880== 
==4880== Invalid read of size 8
==4880==    at 0x5BE2F43: __intel_new_memcpy (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6C60900: ttcacs (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6C2F5F4: ttcdrv (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BDD9B8: nioqwa (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BB95C6: upirtrc (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BC5155: kpurcsc (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BBE56B: kpuexec (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BBA06A: OCIStmtExecute (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x4C605DA: OCI_ExecuteInternal (statement.c:1923)
==4880==    by 0x4C60C57: OCI_Execute (statement.c:2149)
==4880==    by 0x4087D1: ocilib::Statement::ExecutePrepared() (ocilib_impl.hpp:4518)
==4880==    by 0x4057A1: main (BigRaw.cpp:113)
==4880==  Address 0x833872c is 2 bytes after a block of size 10 alloc'd
==4880==    at 0x4A07152: operator new[](unsigned long) (vg_replace_malloc.c:363)
==4880==    by 0x40E924: ocilib::BindArray::BindArrayObject<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned char>::AllocData() (ocilib_impl.hpp:4109)
==4880==    by 0x40C17B: ocilib::BindArray::BindArrayObject<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned char>::BindArrayObject(ocilib::Statement const&, std::string const&, std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&, unsigned int, unsigned int) (ocilib_impl.hpp:4097)
==4880==    by 0x40A410: void ocilib::BindArray::SetVector<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned char>(std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&, unsigned int, unsigned int) (ocilib_impl.hpp:4069)
==4880==    by 0x4089F7: void ocilib::Statement::Bind<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned int>(std::string const&, std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&, unsigned int, ocilib::Enum<ocilib::BindInfo::BindDirectionValues>) (ocilib_impl.hpp:5101)
==4880==    by 0x40577A: main (BigRaw.cpp:112)
==4880== 
==4880== Invalid read of size 8
==4880==    at 0x5BE2F5A: __intel_new_memcpy (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6C60900: ttcacs (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6C2F5F4: ttcdrv (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BDD9B8: nioqwa (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BB95C6: upirtrc (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BC5155: kpurcsc (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BBE56B: kpuexec (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BBA06A: OCIStmtExecute (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x4C605DA: OCI_ExecuteInternal (statement.c:1923)
==4880==    by 0x4C60C57: OCI_Execute (statement.c:2149)
==4880==    by 0x4087D1: ocilib::Statement::ExecutePrepared() (ocilib_impl.hpp:4518)
==4880==    by 0x4057A1: main (BigRaw.cpp:113)
==4880==  Address 0x8338730 is 6 bytes after a block of size 10 alloc'd
==4880==    at 0x4A07152: operator new[](unsigned long) (vg_replace_malloc.c:363)
==4880==    by 0x40E924: ocilib::BindArray::BindArrayObject<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned char>::AllocData() (ocilib_impl.hpp:4109)
==4880==    by 0x40C17B: ocilib::BindArray::BindArrayObject<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned char>::BindArrayObject(ocilib::Statement const&, std::string const&, std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&, unsigned int, unsigned int) (ocilib_impl.hpp:4097)
==4880==    by 0x40A410: void ocilib::BindArray::SetVector<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned char>(std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&, unsigned int, unsigned int) (ocilib_impl.hpp:4069)
==4880==    by 0x4089F7: void ocilib::Statement::Bind<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned int>(std::string const&, std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&, unsigned int, ocilib::Enum<ocilib::BindInfo::BindDirectionValues>) (ocilib_impl.hpp:5101)
==4880==    by 0x40577A: main (BigRaw.cpp:112)
==4880== Invalid read of size 8
==4880==    at 0x5BE3394: __intel_new_memcpy (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6C60900: ttcacs (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6C2F5F4: ttcdrv (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BDD9B8: nioqwa (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BB95C6: upirtrc (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BC5155: kpurcsc (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BBE56B: kpuexec (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BBA06A: OCIStmtExecute (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x4C605DA: OCI_ExecuteInternal (statement.c:1923)
==4880==    by 0x4C60C57: OCI_Execute (statement.c:2149)
==4880==    by 0x4087D1: ocilib::Statement::ExecutePrepared() (ocilib_impl.hpp:4518)
==4880==    by 0x4057A1: main (BigRaw.cpp:113)
==4880==  Address 0x8338740 is 22 bytes after a block of size 10 alloc'd
==4880==    at 0x4A07152: operator new[](unsigned long) (vg_replace_malloc.c:363)
==4880==    by 0x40E924: ocilib::BindArray::BindArrayObject<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned char>::AllocData() (ocilib_impl.hpp:4109)
==4880==    by 0x40C17B: ocilib::BindArray::BindArrayObject<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned char>::BindArrayObject(ocilib::Statement const&, std::string const&, std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&, unsigned int, unsigned int) (ocilib_impl.hpp:4097)
==4880==    by 0x40A410: void ocilib::BindArray::SetVector<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned char>(std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&, unsigned int, unsigned int) (ocilib_impl.hpp:4069)
==4880==    by 0x4089F7: void ocilib::Statement::Bind<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned int>(std::string const&, std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&, unsigned int, ocilib::Enum<ocilib::BindInfo::BindDirectionValues>) (ocilib_impl.hpp:5101)
==4880==    by 0x40577A: main (BigRaw.cpp:112)
==4880== 
==4880== Invalid read of size 8
==4880==    at 0x5BE3399: __intel_new_memcpy (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6C60900: ttcacs (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6C2F5F4: ttcdrv (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BDD9B8: nioqwa (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BB95C6: upirtrc (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BC5155: kpurcsc (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BBE56B: kpuexec (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BBA06A: OCIStmtExecute (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x4C605DA: OCI_ExecuteInternal (statement.c:1923)
==4880==    by 0x4C60C57: OCI_Execute (statement.c:2149)
==4880==    by 0x4087D1: ocilib::Statement::ExecutePrepared() (ocilib_impl.hpp:4518)
==4880==    by 0x4057A1: main (BigRaw.cpp:113)
==4880==  Address 0x8338750 is not stack'd, malloc'd or (recently) free'd
==4880== 
==4880== Invalid read of size 2
==4880==    at 0x5BE2B27: __intel_new_memcpy (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6C60900: ttcacs (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6C2F5F4: ttcdrv (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BDD9B8: nioqwa (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BB95C6: upirtrc (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BC5155: kpurcsc (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BBE56B: kpuexec (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x6BBA06A: OCIStmtExecute (in /vobs/thirdparty/oracle/instantclient/installed/instantclient_11_2/linux/libclntsh.so.11.1)
==4880==    by 0x4C605DA: OCI_ExecuteInternal (statement.c:1923)
==4880==    by 0x4C60C57: OCI_Execute (statement.c:2149)
==4880==    by 0x4087D1: ocilib::Statement::ExecutePrepared() (ocilib_impl.hpp:4518)
==4880==    by 0x4057A1: main (BigRaw.cpp:113)
==4880==  Address 0x833881c is 20 bytes after a block of size 152 alloc'd
==4880==    at 0x4A069EE: malloc (vg_replace_malloc.c:270)
==4880==    by 0x4C4AB8C: OCI_MemAlloc (memory.c:70)
==4880==    by 0x4C5E1FB: OCI_BindData (statement.c:793)
==4880==    by 0x4C631E7: OCI_BindArrayOfRaws (statement.c:2948)
==4880==    by 0x408A3A: void ocilib::Statement::Bind<std::vector<unsigned char, std::allocator<unsigned char> >, unsigned int>(std::string const&, std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >&, unsigned int, ocilib::Enum<ocilib::BindInfo::BindDirectionValues>) (ocilib_impl.hpp:5103)
==4880==    by 0x40577A: main (BigRaw.cpp:112)
==4880== 
...
@kornefalk
Copy link
Author

Wrong memory size is allocated when binding vector in ocilib_impl.hpp. For example if binding 10 Raw rows with a length of up to 2000 bytes, only 10 bytes are allocated instead of 20 000 bytes.

template <class TObjectType, class TDataType>
inline void BindArray::BindArrayObject<TObjectType, TDataType>::AllocData()
{
    _data = new TDataType[_elemCount];

    memset(_data, 0, sizeof(TDataType) * _elemCount);
}

Must be

template <class TObjectType, class TDataType>
inline void BindArray::BindArrayObject<TObjectType, TDataType>::AllocData()
{
    _data = new TDataType[_elemCount * _elemSize];

    memset(_data, 0, sizeof(TDataType) * _elemCount * _elemSize);
}

@vrogier
Copy link
Owner

vrogier commented Sep 14, 2015

Hi,

Thanks :)

The funny thing is that I was going to commit a fix at the same time i got your mail.

I've looked at the pull request. My fix is slightly different and address also the Raw size when fetched after insert.
In you sample code a Raw with size 650 once inserted and fetched later is returned with size 2000 which was the max size at insert time. I've fixed that as well.
See my latest commit.

Thanks again for reporting issues :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants