Skip to content

Commit 2636104

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
2 parents 4306416 + 42443b4 commit 2636104

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ PHP NEWS
6666
ext/session/mod_files.c). (nielsdos)
6767
. Fixed bug GH-13891 (memleak and segfault when using ini_set with
6868
session.trans_sid_hosts). (nielsdos, kamil-tekiela)
69+
. Fixed buffer _read/_write size limit on windows for the file mode. (David Carlier)
6970

7071
- Streams:
7172
. Fixed file_get_contents() on Windows fails with "errno=22 Invalid

ext/session/mod_files.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
# ifndef O_NOFOLLOW
8787
# define O_NOFOLLOW 0
8888
# endif
89+
#define SESS_FILE_BUF_SIZE(sz) ((unsigned int)(sz > INT_MAX ? INT_MAX : (unsigned int)sz))
8990
#endif
9091

9192
typedef struct {
@@ -246,7 +247,7 @@ static zend_result ps_files_write(ps_files *data, zend_string *key, zend_string
246247
lseek(data->fd, 0, SEEK_SET);
247248
#ifdef PHP_WIN32
248249
{
249-
unsigned int to_write = ZSTR_LEN(val) > UINT_MAX ? UINT_MAX : (unsigned int)ZSTR_LEN(val);
250+
unsigned int to_write = SESS_FILE_BUF_SIZE(ZSTR_LEN(val));
250251
char *buf = ZSTR_VAL(val);
251252
int wrote;
252253

@@ -255,7 +256,7 @@ static zend_result ps_files_write(ps_files *data, zend_string *key, zend_string
255256

256257
n += wrote;
257258
buf = wrote > -1 ? buf + wrote : 0;
258-
to_write = wrote > -1 ? (ZSTR_LEN(val) - n > UINT_MAX ? UINT_MAX : (unsigned int)(ZSTR_LEN(val) - n)): 0;
259+
to_write = wrote > -1 ? SESS_FILE_BUF_SIZE(ZSTR_LEN(val) - n) : 0;
259260

260261
} while(wrote > 0);
261262
}
@@ -493,7 +494,7 @@ PS_READ_FUNC(files)
493494
lseek(data->fd, 0, SEEK_SET);
494495
#ifdef PHP_WIN32
495496
{
496-
unsigned int to_read = ZSTR_LEN(*val) > UINT_MAX ? UINT_MAX : (unsigned int)ZSTR_LEN(*val);
497+
unsigned int to_read = SESS_FILE_BUF_SIZE(ZSTR_LEN(*val));
497498
char *buf = ZSTR_VAL(*val);
498499
int read_in;
499500

@@ -502,7 +503,7 @@ PS_READ_FUNC(files)
502503

503504
n += read_in;
504505
buf = read_in > -1 ? buf + read_in : 0;
505-
to_read = read_in > -1 ? (ZSTR_LEN(*val) - n > UINT_MAX ? UINT_MAX : (unsigned int)(ZSTR_LEN(*val) - n)): 0;
506+
to_read = read_in > -1 ? SESS_FILE_BUF_SIZE(ZSTR_LEN(*val) - n) : 0;
506507

507508
} while(read_in > 0);
508509

0 commit comments

Comments
 (0)