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

ibm_db 2.6.1 blob data corrupted #582

Closed
wnwaynelee opened this issue Oct 7, 2019 · 8 comments
Closed

ibm_db 2.6.1 blob data corrupted #582

wnwaynelee opened this issue Oct 7, 2019 · 8 comments

Comments

@wnwaynelee
Copy link

Steps to reproduce the problem in 2.6.1

  1. edit node_modules\ibm_db\test\config.testConnectionStrings.json to set the db configuration
  2. cd node_modules\ibm_db\test
  3. node test-blob-insert.js
    The output is

img1.length = 685239
text.length = 841665
buffer data = 49 49 2A 00 C8 8C 00 00 73 C5 3C 13 83 39 98 35
Lengths after select = 1038449, 841665
buffer after select : 49 49 2A 00 C8 8C 00 00 73 C5 3C 13 83 39 98 35
done

Note that the img1.length is 685239 while the Lengths after select is 1038449. Setting DB2CODEPAGE=1208 according to #579 does not help.

With 2.5.3, the output is

img1.length = 685239
text.length = 841665
buffer data = 49 49 2A 00 C8 8C 00 00 73 C5 3C 13 83 39 98 35
Lengths after select = 685239, 841665
buffer after select : 49 49 2A 00 C8 8C 00 00 73 C5 3C 13 83 39 98 35
done

Note that the img1.length is identical to the Lengths after select.

@bimalkjha
Copy link
Member

@wnwaynelee This test case is working fine for me on Windows, Linux and Macos. I am unable to reproduce it. Could you please provide little bit more detail to reproduce it like node.js version, OS name, have installed any db2 client or server in the system, your db2 server is local or remote etc. Thanks.

@wnwaynelee
Copy link
Author

@bimalkjha My node.js is v10.16.3 running on Windows 10 Enterprise 1903 build 18362.295. There is no db2 client installed on Windows. Node.js is using the prebuild binary from ibm_db. My db2 is v11.5.0.0 on Docker 19.03.2 on Ubuntu 18.04.3 LTS. Thanks.

@wnwaynelee
Copy link
Author

@bimalkjha To rule out that this is an OS or node version issue, I tried
node.js v12.9.1 running on Windows 10 Enterprise 1903 build 18362.295
node.js v10.16.3 running on Ubuntu 18.04.3 LTS
The results are the same, ibm_db 2.5.3 works and 2.6.1 doesn't.
Thanks.

@bimalkjha
Copy link
Member

@wnwaynelee Thanks for sharing the info. I am able to reproduce the issue. I am curious to know why the assert at line https://github.com/ibmdb/node-ibm_db/blob/master/test/test-blob-insert.js#L87 do not fail? Because of this non working assert, test case was passing in batch run.
Thanks for reporting the issue. We'll fix it soon and update you.

@bimalkjha
Copy link
Member

Looks the issue is due to copying of binary data in utf8string by https://github.com/ibmdb/node-ibm_db/blob/master/src/odbc.cpp#L987. Conversion of binary to utf8 causes expansion of data and getting corrupted.
@bnoordhuis Any idea how to read binary data from js object to c++ here and get its length? Thanks.

@bnoordhuis
Copy link
Contributor

@bimalkjha Nan only has Utf8String because old versions of Node.js only support UTF-8. If you're okay with using the V8 API directly, you can use v8::String::WriteOneByte():

https://github.com/nodejs/node/blob/31217a8e88d7414579284267f8715112bf8a0fc6/deps/v8/include/v8.h#L2812-L2814

Caveat emptor: it doesn't take an Isolate* as its argument in Node.js v8.x so you'll need to #include "node_version.h" and then guard on NODE_MAJOR_VERSION > 8.

bimalkjha added a commit that referenced this issue Oct 23, 2019
@bimalkjha
Copy link
Member

@wnwaynelee I have delivered the fix for this issue on github. It would be part of next release.
You may install the latest code using command npm install git+https://[email protected]/ibmdb/node-ibm_db.git and verify the fix. Thanks.

bimalkjha added a commit that referenced this issue Dec 3, 2019
* doc: Docker Linux Container instructions

* support for install --debug option on windows

* fix: blob data corruption issue #582

* doc: update doc for executeNonQuerySync API, issue #583

* force push connection to the queue when poolSize breaches maxPool boundry (#581)

* Support for node v12 on z/OS, and fix some test cases for z/OS (#586)

* fix: update unzipper version, issue #588

* fix: use v8::Isolate for nodev >= 11

* fix: ignore sqlcode 100 by executeNonQuery, issue #591

* fix: add executeNonQuerySync in odbc.js issue #595
bimalkjha added a commit that referenced this issue Dec 9, 2019
 * doc: update for issue #593 (Bimal Jha)
 * fix: update windows binary using latest code (Bimal Jha)
 * fix: for memory leak issue #576 (Bimal Jha)
 * fix: update windows binary for vscode 1.40.x (Bimal Jha)
 * update windows binaries (Bimal Jha)
 * fix: add executeNonQuerySync in odbc.js issue #595 (Bimal Jha)
 * fix: ignore sqlcode 100 by executeNonQuery, issue #591 (Bimal Jha)
 * fix: use v8::Isolate for nodev >= 11 (Bimal Jha)
 * fix: update unzipper version, issue #588 (Bimal Jha)
 * Support for node v12 on z/OS, and fix some test cases for z/OS (#586) (alexcfyung)
 * force push connection to the queue when poolSize breaches maxPool boundry (#581) (ashutoshrnjn)
 * doc: update doc for executeNonQuerySync API, issue #583 (Bimal Jha)
 * fix: blob data corruption issue #582 (Bimal Jha)
 * support for install --debug option on windows (Priyanka Manoharan)
 * doc: Docker Linux Container instructions (Bimal Jha)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants