Skip to content

Commit 16d7b94

Browse files
committed
Fix CLOB crash due to incorrectly sized buffer
1 parent 8443b18 commit 16d7b94

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/dpi/include/dpiLob.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ class Lob
6767
unsigned long long &byteAmount,
6868
unsigned long long &charAmount,
6969
unsigned long long offset,
70-
void *buf);
70+
void *buf,
71+
unsigned long long bufl);
7172

7273
static void write(DpiHandle *svch, DpiHandle *errh, Descriptor *lobLocator,
7374
unsigned long long &byteAmount,
7475
unsigned long long &charAmount,
7576
unsigned long long offset,
76-
void *buf);
77+
void *buf,
78+
unsigned long long bufl);
7779

7880
static unsigned int chunkSize(DpiHandle *svch, DpiHandle *errh,
7981
Descriptor *lobLocator);

src/dpi/src/dpiLob.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,12 @@ using namespace dpi;
7979

8080
void Lob::read(DpiHandle *svch, DpiHandle *errh, Descriptor *lobLocator,
8181
unsigned long long &byteAmount, unsigned long long &charAmount,
82-
unsigned long long offset, void *buf)
82+
unsigned long long offset, void *buf, unsigned long long bufl)
8383
{
8484
ociCall(OCILobRead2((OCISvcCtx *)svch, (OCIError *)errh,
8585
(OCILobLocator *)lobLocator,
8686
(oraub8 *)&byteAmount, (oraub8 *)&charAmount,
87-
// for CLOBs, buflen is sized to handle multi-byte charsets
88-
offset, buf, byteAmount ? byteAmount : charAmount*4,
87+
offset, buf, (oraub8)(byteAmount ? byteAmount : bufl),
8988
OCI_ONE_PIECE, NULL, NULL, 0, SQLCS_IMPLICIT),
9089
(OCIError *)errh);
9190
}
@@ -127,13 +126,12 @@ void Lob::read(DpiHandle *svch, DpiHandle *errh, Descriptor *lobLocator,
127126

128127
void Lob::write(DpiHandle *svch, DpiHandle *errh, Descriptor *lobLocator,
129128
unsigned long long &byteAmount, unsigned long long &charAmount,
130-
unsigned long long offset, void *buf)
129+
unsigned long long offset, void *buf, unsigned long long bufl)
131130
{
132131
ociCall(OCILobWrite2((OCISvcCtx *)svch, (OCIError *)errh,
133132
(OCILobLocator *)lobLocator,
134133
(oraub8 *)&byteAmount, (oraub8 *)&charAmount,
135-
// for CLOBs, buflen is sized to handle multi-byte charsets
136-
offset, buf, byteAmount ? byteAmount : charAmount*4,
134+
offset, buf, (oraub8)(byteAmount ? byteAmount : bufl),
137135
OCI_ONE_PIECE, NULL, NULL, 0, SQLCS_IMPLICIT),
138136
(OCIError *)errh);
139137
}

src/njs/src/njsIntLob.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,16 +896,19 @@ void ILob::Async_Read(uv_work_t *req)
896896
{
897897
unsigned long long byteAmount = (unsigned long int)iLob->bufSize_;
898898
unsigned long long charAmount = 0;
899+
unsigned long long bufl = 0;
899900

900901
// Clobs read by characters
901902
if (iLob->fetchType_ == DpiClob)
902903
{
903904
charAmount = iLob->bufSize_;
904905
byteAmount = 0;
906+
// for CLOBs, buflen is adjusted to handle multi-byte charsets
907+
bufl = charAmount * iLob->dpiconn_->getByteExpansionRatio();
905908
}
906909
Lob::read((DpiHandle *)iLob->svch_, (DpiHandle *)iLob->errh_,
907910
(Descriptor *)iLob->lobLocator_, byteAmount, charAmount,
908-
iLob->offset_, (void *)iLob->buf_);
911+
iLob->offset_, (void *)iLob->buf_, bufl);
909912

910913
// amountRead_ used in Async_AfterRead to construct string
911914
iLob->amountRead_ = (unsigned long)byteAmount;
@@ -1087,10 +1090,13 @@ void ILob::Async_Write(uv_work_t *req)
10871090
{
10881091
unsigned long long byteAmount = lobBaton->writelen;
10891092
unsigned long long charAmount = 0; // interested in byte amount only
1093+
// for CLOBs, buflen is adjusted to handle multi-byte charsets
1094+
unsigned long long bufl = charAmount *
1095+
iLob->dpiconn_->getByteExpansionRatio();
10901096

10911097
Lob::write((DpiHandle *)iLob->svch_, (DpiHandle *)iLob->errh_,
10921098
(Descriptor *)iLob->lobLocator_, byteAmount, charAmount,
1093-
iLob->offset_, lobBaton->writebuf);
1099+
iLob->offset_, lobBaton->writebuf, bufl);
10941100

10951101

10961102
iLob->amountWritten_ = (unsigned long)byteAmount;

0 commit comments

Comments
 (0)