Skip to content

Commit 023200b

Browse files
authored
Fix fileobj I/O un-deterministic behavior (#1305)
1 parent 6bcadb9 commit 023200b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

third_party/sox/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ ExternalProject_Add(sox
197197
URL https://downloads.sourceforge.net/project/sox/sox/14.4.2/sox-14.4.2.tar.bz2
198198
URL_HASH SHA256=81a6956d4330e75b5827316e44ae381e6f1e8928003c6aa45896da9041ea149c
199199
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env ${envs} ${CMAKE_CURRENT_BINARY_DIR}/src/sox/configure ${COMMON_ARGS} ${SOX_OPTIONS}
200+
PATCH_COMMAND patch -p1 < ${CMAKE_CURRENT_SOURCE_DIR}/patch/sox.patch
200201
BUILD_BYPRODUCTS ${SOX_LIBRARIES}
201202
DOWNLOAD_NO_PROGRESS ON
202203
LOG_DOWNLOAD ON

third_party/sox/patch/sox.patch

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
See https://github.com/pytorch/audio/pull/1297
2+
diff -ru sox/src/formats.c sox/src/formats.c
3+
--- sox/src/formats.c 2014-10-26 19:55:50.000000000 -0700
4+
+++ sox/src/formats.c 2021-02-22 16:01:02.833144070 -0800
5+
@@ -333,6 +333,10 @@
6+
assert(ft);
7+
if (!ft->fp)
8+
return sox_false;
9+
- fstat(fileno((FILE*)ft->fp), &st);
10+
+ int fd = fileno((FILE*)ft->fp);
11+
+ if (fd < 0)
12+
+ return sox_false;
13+
+ if (fstat(fd, &st) < 0)
14+
+ return sox_false;
15+
return ((st.st_mode & S_IFMT) == S_IFREG);
16+
}

0 commit comments

Comments
 (0)