8000 Bug #61566 Fileinfo ext\fileinfo\tests\finfo_file_002.phpt fails · php/php-src@dcdd6da · GitHub
[go: up one dir, main page]

Skip to content

Commit dcdd6da

Browse files
weltlingsmalyshev
authored andcommitted
Bug #61566 Fileinfo ext\fileinfo\tests\finfo_file_002.phpt fails
This patch fixes the failure caused by the posix lseek and read versions under windows in cdf_read() . Additionally all the occurences of lseek and read was replaced by _lseek and _reed for windows.
1 parent ea3e0d5 commit dcdd6da

File tree

6 files changed

+40
-32
lines changed

6 files changed

+40
-32
lines changed

ext/fileinfo/libmagic/cdf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,10 @@ cdf_read(const cdf_info_t *info, off_t off, void *buf, size_t len)
306306
if (info->i_fd == -1)
307307
return -1;
308308

309-
if (lseek(info->i_fd, off, SEEK_SET) == (off_t)-1)
309+
if (FINFO_LSEEK_FUNC(info->i_fd, off, SEEK_SET) == (off_t)-1)
310310
return -1;
311311

312-
if (read(info->i_fd, buf, len) != (ssize_t)len)
312+
if (FINFO_READ_FUNC(info->i_fd, buf, len) != (ssize_t)len)
313313
return -1;
314314

315315
return (ssize_t)len;

ext/fileinfo/libmagic/compress.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ sread(int fd, void *buf, size_t n, int canbepipe)
224224

225225
nocheck:
226226
do
227-
switch ((rv = read(fd, buf, n))) {
227+
switch ((rv = FINFO_READ_FUNC(fd, buf, n))) {
228228
case -1:
229229
if (errno == EINTR)
230230
continue;
@@ -301,7 +301,7 @@ file_pipe2file(struct magic_set *ms, int fd, const void *startbuf,
301301
return -1;
302302
}
303303
(void)close(tfd);
304-
if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) {
304+
if (FINFO_LSEEK_FUNC(fd, (off_t)0, SEEK_SET) == (off_t)-1) {
305305
file_badseek(ms);
306306
return -1;
307307
}
@@ -405,7 +405,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
405405
(void) close(0);
406406
if (fd != -1) {
407407
(void) dup(fd);
408-
(void) lseek(0, (off_t)0, SEEK_SET);
408+
(void) FINFO_LSEEK_FUNC(0, (off_t)0, SEEK_SET);
409409
} else {
410410
(void) dup(fdin[0]);
411411
(void) close(fdin[0]);

ext/fileinfo/libmagic/file.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,12 @@ static const char *rcsid(const char *p) { \
486486
#define FILE_RCSID(id)
487487
#endif
488488

489+
#ifdef PHP_WIN32
490+
#define FINFO_LSEEK_FUNC _lseek
491+
#define FINFO_READ_FUNC _read
492+
#else
493+
#define FINFO_LSEEK_FUNC lseek
494+
#define FINFO_READ_FUNC read
495+
#endif
496+
489497
#endif /* __file_h__ */

ext/fileinfo/libmagic/readelf.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,11 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
309309
* Loop through all the program headers.
310310
*/
311311
for ( ; num; num--) {
312-
if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
312+
if (FINFO_LSEEK_FUNC(fd, off, SEEK_SET) == (off_t)-1) {
313313
file_badseek(ms);
314314
return -1;
315315
}
316-
if (read(fd, xph_addr, xph_sizeof) == -1) {
316+
if (FINFO_READ_FUNC(fd, xph_addr, xph_sizeof) == -1) {
317317
file_badread(ms);
318318
return -1;
319319
}
@@ -331,11 +331,11 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
331331
* This is a PT_NOTE section; loop through all the notes
332332
* in the section.
333333
*/
334-
if (lseek(fd, xph_offset, SEEK_SET) == (off_t)-1) {
334+
if (FINFO_LSEEK_FUNC(fd, xph_offset, SEEK_SET) == (off_t)-1) {
335335
file_badseek(ms);
336336
return -1;
337337
}
338-
bufsize = read(fd, nbuf,
338+
bufsize = FINFO_READ_FUNC(fd, nbuf,
339339
((xph_filesz < sizeof(nbuf)) ? xph_filesz : sizeof(nbuf)));
340340
if (bufsize == -1) {
341341
file_badread(ms);
@@ -858,11 +858,11 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
858858
}
859859

860860
for ( ; num; num--) {
861-
if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
861+
if (FINFO_LSEEK_FUNC(fd, off, SEEK_SET) == (off_t)-1) {
862862
file_badseek(ms);
863863
return -1;
864864
}
865-
if (read(fd, xsh_addr, xsh_sizeof) == -1) {
865+
if (FINFO_READ_FUNC(fd, xsh_addr, xsh_sizeof) == -1) {
866866
file_badread(ms);
867867
return -1;
868868
}
@@ -888,13 +888,13 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
888888
switch (xsh_type) {
889889
case SHT_NOTE:
890890
nbuf = emalloc((size_t)xsh_size);
891-
if ((noff = lseek(fd, (off_t)xsh_offset, SEEK_SET)) ==
891+
if ((noff = FINFO_LSEEK_FUNC(fd, (off_t)xsh_offset, SEEK_SET)) ==
892892
(off_t)-1) {
893893
file_badread(ms);
894894
efree(nbuf);
895895
return -1;
896896
}
897-
if (read(fd, nbuf, (size_t)xsh_size) !=
897+
if (FINFO_READ_FUNC(fd, nbuf, (size_t)xsh_size) !=
898898
(ssize_t)xsh_size) {
899899
efree(nbuf);
900900
file_badread(ms);
@@ -914,7 +914,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
914914
efree(nbuf);
915915
break;
916916
case SHT_SUNW_cap:
917-
if (lseek(fd, (off_t)xsh_offset, SEEK_SET) ==
917+
if (FINFO_LSEEK_FUNC(fd, (off_t)xsh_offset, SEEK_SET) ==
918918
(off_t)-1) {
919919
file_badseek(ms);
920920
return -1;
@@ -927,7 +927,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
927927
MAX(sizeof cap32, sizeof cap64)];
928928
if ((coff += xcap_sizeof) > (off_t)xsh_size)
929929
break;
930-
if (read(fd, cbuf, (size_t)xcap_sizeof) !=
930+
if (FINFO_READ_FUNC(fd, cbuf, (size_t)xcap_sizeof) !=
931931
(ssize_t)xcap_sizeof) {
932932
file_badread(ms);
933933
return -1;
@@ -1046,12 +1046,12 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
10461046
}
10471047

10481048
for ( ; num; num--) {
1049-
if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
1049+
if (FINFO_LSEEK_FUNC(fd, off, SEEK_SET) == (off_t)-1) {
10501050
file_badseek(ms);
10511051
return -1;
10521052
}
10531053

1054-
if (read(fd, xph_addr, xph_sizeof) == -1) {
1054+
if (FINFO_READ_FUNC(fd, xph_addr, xph_sizeof) == -1) {
10551055
file_badread(ms);
10561056
return -1;
10571057
}
@@ -1090,11 +1090,11 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
10901090
* This is a PT_NOTE section; loop through all the notes
10911091
* in the section.
10921092
*/
1093-
if (lseek(fd, xph_offset, SEEK_SET) == (off_t)-1) {
1093+
if (FINFO_LSEEK_FUNC(fd, xph_offset, SEEK_SET) == (off_t)-1) {
10941094
file_badseek(ms);
10951095
return -1;
10961096
}
1097-
bufsize = read(fd, nbuf, ((xph_filesz < sizeof< 10000 /span>(nbuf)) ?
1097+
bufsize = FINFO_READ_FUNC(fd, nbuf, ((xph_filesz < sizeof(nbuf)) ?
10981098
xph_filesz : sizeof(nbuf)));
10991099
if (bufsize == -1) {
11001100
file_badread(ms);
@@ -1156,7 +1156,7 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
11561156
/*
11571157
* If we cannot seek, it must be a pipe, socket or fifo.
11581158
*/
1159-
if((lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE))
1159+
if((FINFO_LSEEK_FUNC(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE))
11601160
fd = file_pipe2file(ms, fd, buf, nbytes);
11611161

11621162
if (fstat(fd, &st) == -1) {

ext/fileinfo/tests/finfo_open_001.phpt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ bool(false)
1919
resource(%d) of type (file_info)
2020
resource(%d) of type (file_info)
2121

22-
Warning: finfo_open(%s/123): failed to open stream: No such file or directory in %s on line %d
22+
Warning: finfo_open(%s123): failed to open stream: No such file or directory in %s on line %d
2323

24-
Warning: finfo_open(%s/123): failed to open stream: No such file or directory in %s on line %d
24+
Warning: finfo_open(%s123): failed to open stream: No such file or directory in %s on line %d
2525

26-
Warning: finfo_open(): Failed to load magic database at '%s/123'. in %s on line %d
26+
Warning: finfo_open(): Failed to load magic database at '%s123'. in %s on line %d
2727
bool(false)
2828

29-
Warning: finfo_open(%s/1): failed to open stream: No such file or directory in %s on line %d
29+
Warning: finfo_open(%s1): failed to open stream: No such file or directory in %s on line %d
3030

31-
Warning: finfo_open(%s/1): failed to open stream: No such file or directory in %s on line %d
31+
Warning: finfo_open(%s1): failed to open stream: No such file or directory in %s on line %d
3232

33-
Warning: finfo_open(): Failed to load magic database at '%s/1'. in %s on line %d
33+
Warning: finfo_open(): Failed to load magic database at '%s1'. in %s on line %d
3434
bool(false)
3535

36-
Warning: finfo_open(/foo/bar/inexistent): failed to open stream: No such file or directory in %s on line %d
36+
Warning: finfo_open(%sinexistent): failed to open stream: No such file or directory in %s on line %d
3737

38-
Warning: finfo_open(/foo/bar/inexistent): failed to open stream: No such file or directory in %s on line %d
38+
Warning: finfo_open(%sinexistent): failed to open stream: No such file or directory in %s on line %d
3939

40-
Warning: finfo_open(): Failed to load magic database at '/foo/bar/inexistent'. in %s on line %d
40+
Warning: finfo_open(): Failed to load magic database at '%sinexistent'. in %s on line %d
4141
bool(false)

ext/fileinfo/tests/finfo_open_error.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ var_dump( new finfo('foobar') );
2727
--EXPECTF--
2828
*** Testing finfo_open() : error functionality ***
2929

30-
Warning: finfo_open(%s/foobarfile): failed to open stream: No such file or directory in %s on line %d
30+
Warning: finfo_open(%sfoobarfile): failed to open stream: No such file or directory in %s on line %d
3131

32-
Warning: finfo_open(%s/foobarfile): failed to open stream: No such file or directory in %s on line %d
32+
Warning: finfo_open(%sfoobarfile): failed to open stream: No such file or directory in %s on line %d
3333

34-
Warning: finfo_open(): Failed to load magic database at '%s/foobarfile'. in %s on line %d
34+
Warning: finfo_open(): Failed to load magic database at '%sfoobarfile'. in %s on line %d
3535
bool(false)
3636

3737
Warning: finfo_open() expects parameter 1 to be long, array given in %s on line %d

0 commit comments

Comments
 (0)
0