Skip to content

Commit f3f3aae

Browse files
committed
Improve conversions from uint64 to Perl types.
Perl's integers are pointer-sized, so can hold more than INT_MAX on LP64 platforms, and come in both signed (IV) and unsigned (UV). Floating point values (NV) may also be larger than double. Since Perl 5.19.4 array indices are SSize_t instead of I32, so allow up to SSize_t_max on those versions. The limit is not imposed just by av_extend's argument type, but all the array handling code, so remove the speculative comment. Dagfinn Ilmari Mannsåker
1 parent 6be84ee commit f3f3aae

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/pl/plperl/plperl.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,22 +3104,18 @@ plperl_spi_execute_fetch_result(SPITupleTable *tuptable, uint64 processed,
31043104
hv_store_string(result, "status",
31053105
cstr2sv(SPI_result_code_string(status)));
31063106
hv_store_string(result, "processed",
3107-
(processed > (uint64) INT_MAX) ?
3108-
newSVnv((double) processed) :
3109-
newSViv((int) processed));
3107+
(processed > (uint64) UV_MAX) ?
3108+
newSVnv((NV) processed) :
3109+
newSVuv((UV) processed));
31103110

31113111
if (status > 0 && tuptable)
31123112
{
31133113
AV *rows;
31143114
SV *row;
31153115
uint64 i;
31163116

3117-
/*
3118-
* av_extend's 2nd argument is declared I32. It's possible we could
3119-
* nonetheless push more than INT_MAX elements into a Perl array, but
3120-
* let's just fail instead of trying.
3121-
*/
3122-
if (processed > (uint64) INT_MAX)
3117+
/* Prevent overflow in call to av_extend() */
3118+
if (processed > (uint64) AV_SIZE_MAX)
31233119
ereport(ERROR,
31243120
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
31253121
errmsg("query result has too many rows to fit in a Perl array")));

src/pl/plperl/plperl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@
8888
#define GvCV_set(gv, cv) (GvCV(gv) = cv)
8989
#endif
9090

91+
/* Perl 5.19.4 changed array indices from I32 to SSize_t */
92+
#if PERL_BCDVERSION >= 0x5019004
93+
#define AV_SIZE_MAX SSize_t_MAX
94+
#else
95+
#define AV_SIZE_MAX I32_MAX
96+
#endif
97+
9198
/* declare routines from plperl.c for access by .xs files */
9299
HV *plperl_spi_exec(char *, int);
93100
void plperl_return_next(SV *);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy