SCM

[#1011215] AddString in NpgsqlCopySerializer.cs crashes with \ in string

View Trackers | Bugs | Download .csv | Monitor

Date:
2012-08-03 14:25
Priority:
3
State:
Open
Submitted by:
Jelmer Baas (jelmer)
Assigned to:
Nobody (None)
Npgsql Version:
2.0.11
Category:
Group:
Resolution:
Accepted
Summary:
AddString in NpgsqlCopySerializer.cs crashes with \ in string

Detailed description
I'm using v2.0.11.93. No matter how I try to escape the string value, I always receive an exception:

"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: startIndex"

The solution is simple. Change:
int encodedLength = ENCODING_UTF8.GetByteCount(fieldValue.ToCharArray(bufferedUpto, escapeAt));
MakeRoomForBytes(encodedLength);
_sendBufferAt += ENCODING_UTF8.GetBytes(fieldValue, bufferedUpto, escapeAt, _sendBuffer, _sendBufferAt);
bufferedUpto = escapeAt;

To:

int encodedLength = ENCODING_UTF8.GetByteCount(fieldValue.ToCharArray(bufferedUpto, escapeAt - bufferedUpto));
MakeRoomForBytes(encodedLength);
_sendBufferAt += ENCODING_UTF8.GetBytes(fieldValue, bufferedUpto, escapeAt - bufferedUpto, _sendBuffer, _sendBufferAt);
bufferedUpto = escapeAt;

Followup

Message
Date: 2012-08-07 18:38
Sender: Francisco Figueiredo jr.


Thanks, Jelmer Baas and Panda Răzvan for your help with this issue.
Date: 2012-08-07 18:37
Sender: Francisco Figueiredo jr.

Fixed in cvs.

Please give it a try and let me know if it is working for you.
Date: 2012-08-07 09:23
Sender: Panda Răzvan

@Francisco Figueiredo jr.:
It seems the exception I was getting after applying the patch wasn't cause of the content type (xml), it was cause of the size of the AddString data. The xml field I was adding had around 70KB and default buffer was 8KB. I set npgsqlCopySerializer.BufferSize to a high enough value and now it works.
Date: 2012-08-07 09:22
Sender: Jelmer Baas

Francisco,

The StackOverflow issue has been resolved; it was a
buffersize-issue. The modifications I posted above seem to
work fine. I've managed to insert a few million different
records already, plus a few extra XML cases, all without any
problem.
Date: 2012-08-06 18:32
Sender: Francisco Figueiredo jr.

Hi!

Thanks for your feedback and patch!

There is a discussion about this problem in this stackoverflow thread. There is even a user which tried your patch and although it worked for \ n strings, it was giving problems with xml data. Would it be possible for you to have a look and check if you also get this problem? Thanks in advance.

Stackoverflow thread: http://stackoverflow.com/questions/11824967/how-to-use-npgsqlcopyin-with-npgsqlcopyserializer

Attached Files:

Changes:

Field Old Value Date By
ResolutionNone2012-08-07 18:37fxjr
Powered By FusionForge