Skip to content

Commit 7519f25

Browse files
committed
Support blobs over 4GB in the API / protocol / misc helpers
1 parent 40f5be4 commit 7519f25

File tree

11 files changed

+71
-71
lines changed

11 files changed

+71
-71
lines changed

src/alice/alice_meta.epp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,13 @@ static bool snarf_blob(ISC_QUAD* blob_id, TextBuffer& buffer)
407407
if (!blob.open(DB, gds_trans, *blob_id))
408408
return false;
409409

410-
SLONG blob_size;
410+
FB_UINT64 blob_size;
411411
if (!getBlobSize(blob, &blob_size, NULL, NULL))
412412
return false;
413413

414+
if (blob_size > MAX_ULONG)
415+
return false;
416+
414417
FB_SIZE_T len = blob_size;
415418
TEXT* ptr = buffer.getBuffer(blob_size + 1);
416419
while (len)

src/burp/backup.epp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,34 +1269,36 @@ void put_blob( burp_fld* field, ISC_QUAD& blob_id)
12691269
put(tdgbl, (UCHAR) rec_blob);
12701270
put_int32(att_blob_field_number, field->fld_number);
12711271

1272-
ULONG segments = 0, total_length = 0;
1272+
ULONG segments = 0;
1273+
FB_UINT64 total_length = 0;
12731274
USHORT max_segment = 0;
12741275
int blob_type = 0; // 0 - segmented, 1 - stream
12751276
const UCHAR* p = blob_info;
12761277

12771278
UCHAR item;
12781279
while ((item = *p++) != isc_info_end)
12791280
{
1280-
const USHORT l = gds__vax_integer(p, 2);
1281+
const auto l = gds__vax_integer(p, 2);
12811282
p += 2;
1282-
const ULONG n = gds__vax_integer(p, l);
1283+
const auto n = isc_portable_integer(p, l);
12831284
p += l;
1285+
12841286
switch (item)
12851287
{
12861288
case isc_info_blob_max_segment:
1287-
max_segment = n;
1289+
max_segment = (USHORT) n;
12881290
break;
12891291

12901292
case isc_info_blob_type:
1291-
blob_type = n;
1293+
blob_type = (int) n;
12921294
break;
12931295

12941296
case isc_info_blob_num_segments:
1295-
segments = n;
1297+
segments = (ULONG) n;
12961298
break;
12971299

12981300
case isc_info_blob_total_length:
1299-
total_length = n;
1301+
total_length = (FB_UINT64) n;
13001302
break;
13011303

13021304
default:
@@ -1312,12 +1314,7 @@ void put_blob( burp_fld* field, ISC_QUAD& blob_id)
13121314
// our own chunk size. Note, the number of segments returned by information
13131315
// call for stream blob is always unreliable, even for zero-length blobs
13141316
if (blob_type == 1)
1315-
{
1316-
if (total_length != 0)
1317-
segments = (total_length + max_segment - 1) / max_segment;
1318-
else
1319-
segments = 0;
1320-
}
1317+
segments = total_length ? (total_length + max_segment - 1) / max_segment : 0;
13211318

13221319
put_int32(att_blob_max_segment, max_segment);
13231320
put_int32(att_blob_number_segments, segments);

src/common/classes/BlobWrapper.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ bool BlobWrapper::getInfo(FB_SIZE_T items_size, const UCHAR* items,
217217
return m_status->isEmpty();
218218
}
219219

220-
bool BlobWrapper::getSize(SLONG* size, SLONG* seg_count, SLONG* max_seg) const
220+
bool BlobWrapper::getSize(FB_UINT64* size, ULONG* seg_count, USHORT* max_seg) const
221221
{
222222
/**************************************
223223
*
@@ -249,26 +249,26 @@ bool BlobWrapper::getSize(SLONG* size, SLONG* seg_count, SLONG* max_seg) const
249249

250250
for (UCHAR item = *p++; item != isc_info_end && p < end; item = *p++)
251251
{
252-
const USHORT l = gds__vax_integer(p, 2);
252+
const auto l = gds__vax_integer(p, 2);
253253
p += 2;
254-
const SLONG n = gds__vax_integer(p, l);
254+
const auto n = isc_portable_integer(p, l);
255255
p += l;
256256

257257
switch (item)
258258
{
259259
case isc_info_blob_max_segment:
260260
if (max_seg)
261-
*max_seg = n;
261+
*max_seg = (USHORT) n;
262262
break;
263263

264264
case isc_info_blob_num_segments:
265265
if (seg_count)
266-
*seg_count = n;
266+
*seg_count = (ULONG) n;
267267
break;
268268

269269
case isc_info_blob_total_length:
270270
if (size)
271-
*size = n;
271+
*size = (FB_UINT64) n;
272272
break;
273273

274274
default:

src/common/classes/BlobWrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class BlobWrapper
6868
}
6969

7070
bool getInfo(FB_SIZE_T items_size, const UCHAR* items, FB_SIZE_T info_size, UCHAR* blob_info) const;
71-
bool getSize(SLONG* size, SLONG* seg_count, SLONG* max_seg) const;
71+
bool getSize(FB_UINT64* size, ULONG* seg_count, USHORT* max_seg) const;
7272

7373
static bool blobIsNull(const ISC_QUAD& blobid)
7474
{

src/common/classes/UserBlob.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,7 @@ bool UserBlob::getInfo(FB_SIZE_T items_size, const UCHAR* items,
237237
}
238238

239239

240-
bool getBlobSize( const UserBlob& b,
241-
SLONG* size,
242-
SLONG* seg_count,
243-
SLONG* max_seg)
240+
bool getBlobSize(const UserBlob& b, FB_UINT64* size, ULONG* seg_count, USHORT* max_seg)
244241
{
245242
/**************************************
246243
*
@@ -271,25 +268,26 @@ bool getBlobSize( const UserBlob& b,
271268
const UCHAR* const end = buffer + sizeof(buffer);
272269
for (UCHAR item = *p++; item != isc_info_end && p < end; item = *p++)
273270
{
274-
const USHORT l = gds__vax_integer(p, 2);
271+
const auto l = gds__vax_integer(p, 2);
275272
p += 2;
276-
const SLONG n = gds__vax_integer(p, l);
273+
const auto n = isc_portable_integer(p, l);
277274
p += l;
275+
278276
switch (item)
279277
{
280278
case isc_info_blob_max_segment:
281279
if (max_seg)
282-
*max_seg = n;
280+
*max_seg = (USHORT) n;
283281
break;
284282

285283
case isc_info_blob_num_segments:
286284
if (seg_count)
287-
*seg_count = n;
285+
*seg_count = (ULONG) n;
288286
break;
289287

290288
case isc_info_blob_total_length:
291289
if (size)
292-
*size = n;
290+
*size = (FB_UINT64) n;
293291
break;
294292

295293
default:

src/common/classes/UserBlob.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ inline bool UserBlob::getData(FB_SIZE_T len, void* buffer, FB_SIZE_T& real_len)
109109
}
110110

111111
bool getBlobSize( const UserBlob& b,
112-
SLONG* size,
113-
SLONG* seg_count,
114-
SLONG* max_seg);
112+
FB_UINT64* size,
113+
ULONG* seg_count,
114+
USHORT* max_seg);
115115

116116
#endif // FB_USER_BLOB_H
117117

src/remote/remote.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ void RBlobInfo::parseInfo(unsigned int bufferLength, const unsigned char* buffer
923923
c++;
924924
break;
925925
case isc_info_blob_total_length:
926-
total_length = p.getInt();
926+
total_length = p.getBigInt();
927927
c++;
928928
break;
929929
case isc_info_blob_type:

src/remote/remote.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ struct RBlobInfo
267267
UCHAR blob_type;
268268
ULONG num_segments;
269269
ULONG max_segment;
270-
ULONG total_length;
270+
FB_UINT64 total_length;
271271

272272
RBlobInfo()
273273
{

src/remote/server/server.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6113,10 +6113,10 @@ bool rem_port::sendInlineBlob(PACKET* sendL, Rtr* rtr, SQUAD blobId, ULONG maxSi
61136113
if (status.getState() & IStatus::STATE_ERRORS)
61146114
return false;
61156115

6116-
bool segmented;
6117-
ULONG num_segments;
6118-
ULONG max_segment;
6119-
ULONG total_length;
6116+
bool segmented;
6117+
ULONG num_segments;
6118+
ULONG max_segment;
6119+
FB_UINT64 total_length;
61206120

61216121
ClumpletReader p(ClumpletReader::InfoResponse, info, sizeof(info));
61226122
for (; !p.isEof(); p.moveNext())
@@ -6130,7 +6130,7 @@ bool rem_port::sendInlineBlob(PACKET* sendL, Rtr* rtr, SQUAD blobId, ULONG maxSi
61306130
max_segment = p.getInt();
61316131
break;
61326132
case isc_info_blob_total_length:
6133-
total_length = p.getInt();
6133+
total_length = p.getBigInt();
61346134
break;
61356135
case isc_info_blob_type:
61366136
segmented = (p.getInt() == 0);
@@ -6151,7 +6151,7 @@ bool rem_port::sendInlineBlob(PACKET* sendL, Rtr* rtr, SQUAD blobId, ULONG maxSi
61516151
if (!segmented)
61526152
num_segments = (total_length + max_segment - 1) / max_segment;
61536153

6154-
const ULONG dataLen = total_length + num_segments * 2;
6154+
const FB_UINT64 dataLen = total_length + num_segments * 2;
61556155

61566156
fb_assert(maxSize <= MAX_INLINE_BLOB_SIZE);
61576157
if (maxSize > MAX_INLINE_BLOB_SIZE)

src/utilities/gstat/dba.epp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,33 +1726,28 @@ static USHORT get_format_length(ISC_STATUS* status_vector, isc_db_handle databas
17261726
UserBlob blob(status_vector);
17271727

17281728
if (!blob.open(database, transaction, blob_id))
1729-
{
17301729
return 0;
1731-
}
17321730

17331731
const UCHAR blob_items[] = {isc_info_blob_total_length};
17341732
UCHAR blob_info[BUFFER_TINY];
17351733
if (!blob.getInfo(sizeof(blob_items), blob_items, sizeof(blob_info), blob_info))
1736-
{
17371734
return 0;
1738-
}
17391735

17401736
const UCHAR* p = blob_info;
17411737
if (*p++ != isc_info_blob_total_length)
1742-
{
17431738
return 0;
1744-
}
17451739

1746-
const USHORT l = isc_vax_integer((const char*) p, 2);
1740+
const auto l = isc_vax_integer((const char*) p, 2);
17471741
p += 2;
1748-
const ULONG length = isc_vax_integer((const char*) p, l);
1742+
const auto length = isc_portable_integer(p, l);
1743+
1744+
if (length > MAX_ULONG)
1745+
return 0;
17491746

17501747
FB_SIZE_T return_length = 0;
17511748
Firebird::UCharBuffer buffer;
17521749
if (!blob.getData(length, buffer.getBuffer(length), return_length))
1753-
{
17541750
return 0;
1755-
}
17561751

17571752
buffer.resize(return_length);
17581753

0 commit comments

Comments
 (0)