Skip to content

Commit

Permalink
external libs: rebuild opusfile after mainstream fixes:
Browse files Browse the repository at this point in the history
Updates from https://git.xiph.org/opusfile.git / master branch, and
https://gitlab.xiph.org/tterribe/opusfile.git / misc-fixes-2 branch
(Nothing critical)
  • Loading branch information
sezero committed Nov 17, 2019
1 parent 78771f1 commit 2fccf8e
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 24 deletions.
Binary file modified VisualC/external/lib/x64/libopusfile-0.dll
Binary file not shown.
Binary file modified VisualC/external/lib/x86/libopusfile-0.dll
Binary file not shown.
Binary file modified Xcode/Frameworks/OpusFile.framework/Versions/A/OpusFile
Binary file not shown.
33 changes: 20 additions & 13 deletions external/opusfile-0.11/src/http.c
Expand Up @@ -358,6 +358,11 @@ typedef int op_sock;
# include <sys/timeb.h>
# include <openssl/x509v3.h>

# if (defined(LIBRESSL_VERSION_NUMBER)&&OPENSSL_VERSION_NUMBER==0x20000000L)
# undef OPENSSL_VERSION_NUMBER
# define OPENSSL_VERSION_NUMBER 0x1000115fL
# endif

/*The maximum number of simultaneous connections.
RFC 2616 says this SHOULD NOT be more than 2, but everyone on the modern web
ignores that (e.g., IE 8 bumped theirs up from 2 to 6, Firefox uses 15).
Expand Down Expand Up @@ -1530,15 +1535,15 @@ static long op_bio_retry_ctrl(BIO *_b,int _cmd,long _num,void *_ptr){
return ret;
}

# if OPENSSL_VERSION_NUMBER<0x10100000L
# if (OPENSSL_VERSION_NUMBER<0x10100000L&&LIBRESSL_VERSION_NUMBER<0x2070000fL)
# define BIO_set_data(_b,_ptr) ((_b)->ptr=(_ptr))
# define BIO_set_init(_b,_init) ((_b)->init=(_init))
# define ASN1_STRING_get0_data ASN1_STRING_data
# endif

static int op_bio_retry_new(BIO *_b){
BIO_set_init(_b,1);
# if OPENSSL_VERSION_NUMBER<0x10100000L
# if (OPENSSL_VERSION_NUMBER<0x10100000L&&LIBRESSL_VERSION_NUMBER<0x2070000fL)
_b->num=0;
# endif
BIO_set_data(_b,NULL);
Expand All @@ -1549,7 +1554,7 @@ static int op_bio_retry_free(BIO *_b){
return _b!=NULL;
}

# if OPENSSL_VERSION_NUMBER<0x10100000L
# if (OPENSSL_VERSION_NUMBER<0x10100000L&&LIBRESSL_VERSION_NUMBER<0x2070000fL)
/*This is not const because OpenSSL doesn't allow it, even though it won't
write to it.*/
static BIO_METHOD op_bio_retry_method={
Expand All @@ -1570,7 +1575,7 @@ static BIO_METHOD op_bio_retry_method={
proxying https URL requests.*/
static int op_http_conn_establish_tunnel(OpusHTTPStream *_stream,
OpusHTTPConn *_conn,op_sock _fd,SSL *_ssl_conn,BIO *_ssl_bio){
# if OPENSSL_VERSION_NUMBER>=0x10100000L
# if (OPENSSL_VERSION_NUMBER>=0x10100000L||LIBRESSL_VERSION_NUMBER>=0x2070000fL)
BIO_METHOD *bio_retry_method;
# endif
BIO *retry_bio;
Expand All @@ -1583,7 +1588,7 @@ static int op_http_conn_establish_tunnel(OpusHTTPStream *_stream,
ret=op_http_conn_write_fully(_conn,
_stream->proxy_connect.buf,_stream->proxy_connect.nbuf);
if(OP_UNLIKELY(ret<0))return ret;
# if OPENSSL_VERSION_NUMBER>=0x10100000L
# if (OPENSSL_VERSION_NUMBER>=0x10100000L||LIBRESSL_VERSION_NUMBER>=0x2070000fL)
bio_retry_method=BIO_meth_new(BIO_TYPE_NULL,"retry");
if(bio_retry_method==NULL)return OP_EFAULT;
BIO_meth_set_write(bio_retry_method,op_bio_retry_write);
Expand All @@ -1606,7 +1611,7 @@ static int op_http_conn_establish_tunnel(OpusHTTPStream *_stream,
/*This shouldn't succeed, since we can't read yet.*/
OP_ALWAYS_TRUE(SSL_connect(_ssl_conn)<0);
SSL_set_bio(_ssl_conn,_ssl_bio,_ssl_bio);
# if OPENSSL_VERSION_NUMBER>=0x10100000L
# if (OPENSSL_VERSION_NUMBER>=0x10100000L||LIBRESSL_VERSION_NUMBER>=0x2070000fL)
BIO_meth_free(bio_retry_method);
# endif
/*Only now do we disable write coalescing, to allow the CONNECT
Expand Down Expand Up @@ -1635,7 +1640,7 @@ static struct addrinfo *op_inet_pton(const char *_host){
return NULL;
}

# if OPENSSL_VERSION_NUMBER<0x10002000L
# if (OPENSSL_VERSION_NUMBER<0x10002000L&&LIBRESSL_VERSION_NUMBER<0x2070000fL)
/*Match a host name against a host with a possible wildcard pattern according
to the rules of RFC 6125 Section 6.4.3.
Return: 0 if the pattern doesn't match, and a non-zero value if it does.*/
Expand Down Expand Up @@ -1893,7 +1898,7 @@ static int op_http_conn_start_tls(OpusHTTPStream *_stream,OpusHTTPConn *_conn,
SSL_set_tlsext_host_name(_ssl_conn,_stream->url.host);
# endif
skip_certificate_check=_stream->skip_certificate_check;
# if OPENSSL_VERSION_NUMBER>=0x10002000L
# if (OPENSSL_VERSION_NUMBER>=0x10002000L||LIBRESSL_VERSION_NUMBER>=0x2070000fL)
/*As of version 1.0.2, OpenSSL can finally do hostname checks automatically.
Of course, they make it much more complicated than it needs to be.*/
if(!skip_certificate_check){
Expand Down Expand Up @@ -1956,13 +1961,13 @@ static int op_http_conn_start_tls(OpusHTTPStream *_stream,OpusHTTPConn *_conn,
if(OP_UNLIKELY(ret<=0))return OP_FALSE;
ssl_session=_stream->ssl_session;
if(ssl_session==NULL
# if OPENSSL_VERSION_NUMBER<0x10002000L
# if (OPENSSL_VERSION_NUMBER<0x10002000L&&LIBRESSL_VERSION_NUMBER<0x2070000fL)
||!skip_certificate_check
# endif
){
ret=op_do_ssl_step(_ssl_conn,_fd,SSL_do_handshake);
if(OP_UNLIKELY(ret<=0))return OP_FALSE;
# if OPENSSL_VERSION_NUMBER<0x10002000L
# if (OPENSSL_VERSION_NUMBER<0x10002000L&&LIBRESSL_VERSION_NUMBER<0x2070000fL)
/*OpenSSL before version 1.0.2 does not do automatic hostname verification,
despite the fact that we just passed it the hostname above in the call
to SSL_set_tlsext_host_name().
Expand Down Expand Up @@ -2314,7 +2319,7 @@ static int op_http_stream_open(OpusHTTPStream *_stream,const char *_url,
/*Initialize the SSL library if necessary.*/
if(OP_URL_IS_SSL(&_stream->url)&&_stream->ssl_ctx==NULL){
SSL_CTX *ssl_ctx;
# if OPENSSL_VERSION_NUMBER<0x10100000L
# if (OPENSSL_VERSION_NUMBER<0x10100000L&&LIBRESSL_VERSION_NUMBER<0x2070000fL)
# if !defined(OPENSSL_NO_LOCKING)
/*The documentation says SSL_library_init() is not reentrant.
We don't want to add our own depenencies on a threading library, and it
Expand Down Expand Up @@ -3146,8 +3151,10 @@ static int op_http_stream_seek(void *_stream,opus_int64 _offset,int _whence){
}break;
case SEEK_END:{
/*Check for overflow:*/
if(_offset>content_length||_offset<content_length-OP_INT64_MAX)return -1;
pos=content_length-_offset;
if(_offset<-content_length||_offset>OP_INT64_MAX-content_length){
return -1;
}
pos=content_length+_offset;
}break;
default:return -1;
}
Expand Down
18 changes: 13 additions & 5 deletions external/opusfile-0.11/src/opusfile.c
Expand Up @@ -1533,7 +1533,9 @@ static int op_open1(OggOpusFile *_of,
ogg_sync_wrote(&_of->oy,(long)_initial_bytes);
}
/*Can we seek?
Stevens suggests the seek test is portable.*/
Stevens suggests the seek test is portable.
It's actually not for files on win32, but we address that by fixing it in
our callback implementation (see stream.c).*/
seekable=_cb->seek!=NULL&&(*_cb->seek)(_stream,0,SEEK_CUR)!=-1;
/*If seek is implemented, tell must also be implemented.*/
if(seekable){
Expand Down Expand Up @@ -2818,10 +2820,16 @@ static int op_read_native(OggOpusFile *_of,
/*If we have buffered samples, return them.*/
if(nsamples>0){
if(nsamples*nchannels>_buf_size)nsamples=_buf_size/nchannels;
memcpy(_pcm,_of->od_buffer+nchannels*od_buffer_pos,
sizeof(*_pcm)*nchannels*nsamples);
od_buffer_pos+=nsamples;
_of->od_buffer_pos=od_buffer_pos;
/*Check nsamples again so we don't pass NULL to memcpy() if _buf_size
is zero.
That would technically be undefined behavior, even if the number of
bytes to copy were zero.*/
if(nsamples>0){
memcpy(_pcm,_of->od_buffer+nchannels*od_buffer_pos,
sizeof(*_pcm)*nchannels*nsamples);
od_buffer_pos+=nsamples;
_of->od_buffer_pos=od_buffer_pos;
}
if(_li!=NULL)*_li=_of->cur_link;
return nsamples;
}
Expand Down
63 changes: 57 additions & 6 deletions external/opusfile-0.11/src/stream.c
Expand Up @@ -72,7 +72,7 @@ static int op_fseek(void *_stream,opus_int64 _offset,int _whence){
other libraries (that don't use MSVCRT80 from MSVC 2005 by default).
i686-w64-mingw32 does have fseeko() and respects _FILE_OFFSET_BITS, but I
don't know how to detect that at compile time.
We could just use fseeko64() (which is available in both), but its
We could just use fseeko64() (which is available in both), but it's
implemented using fgetpos()/fsetpos() just like this code, except without
the overflow checking, so we prefer our version.*/
opus_int64 pos;
Expand Down Expand Up @@ -227,6 +227,57 @@ static wchar_t *op_utf8_to_utf16(const char *_src){
return dst;
}

/*fsetpos() internally dispatches to the win32 API call SetFilePointer().
According to SetFilePointer()'s documentation [0], the behavior is
undefined if you do not call it on "a file stored on a seeking device".
However, none of the MSVCRT seeking functions verify what kind of file is
being used before calling it (which I believe is a bug, since they are
supposed to fail and return an error, but it is a bug that has been there
for multiple decades now).
In practice, SetFilePointer() appears to succeed for things like stdin,
even when you are not just piping in a regular file, which prevents the use
of this API to determine whether it is possible to seek in a file at all.
Therefore, we take the approach recommended by the SetFilePointer()
documentation and confirm the type of file using GetFileType() first.
We do this once, when the file is opened, and return the corresponding
callback in order to avoid an extra win32 API call on every seek in the
common case.
Hopefully the return value of GetFileType() cannot actually change for the
lifetime of a file handle.
[0] https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-setfilepointer
*/
static int op_fseek_fail(void *_stream,opus_int64 _offset,int _whence){
(void)_stream;
(void)_offset;
(void)_whence;
return -1;
}

static const OpusFileCallbacks OP_UNSEEKABLE_FILE_CALLBACKS={
op_fread,
op_fseek_fail,
op_ftell,
(op_close_func)fclose
};

# define WIN32_LEAN_AND_MEAN
# define WIN32_EXTRA_LEAN
# include <windows.h>

static const OpusFileCallbacks *op_get_file_callbacks(FILE *_fp){
intptr_t h_file;
h_file=_get_osfhandle(_fileno(_fp));
if(h_file!=-1
&&(GetFileType((HANDLE)h_file)&~FILE_TYPE_REMOTE)==FILE_TYPE_DISK){
return &OP_FILE_CALLBACKS;
}
return &OP_UNSEEKABLE_FILE_CALLBACKS;
}
#else
static const OpusFileCallbacks *op_get_file_callbacks(FILE *_fp){
(void)_fp;
return &OP_FILE_CALLBACKS;
}
#endif

void *op_fopen(OpusFileCallbacks *_cb,const char *_path,const char *_mode){
Expand All @@ -247,14 +298,14 @@ void *op_fopen(OpusFileCallbacks *_cb,const char *_path,const char *_mode){
_ogg_free(wpath);
}
#endif
if(fp!=NULL)*_cb=*&OP_FILE_CALLBACKS;
if(fp!=NULL)*_cb=*op_get_file_callbacks(fp);
return fp;
}

void *op_fdopen(OpusFileCallbacks *_cb,int _fd,const char *_mode){
FILE *fp;
fp=fdopen(_fd,_mode);
if(fp!=NULL)*_cb=*&OP_FILE_CALLBACKS;
if(fp!=NULL)*_cb=*op_get_file_callbacks(fp);
return fp;
}

Expand All @@ -277,7 +328,7 @@ void *op_freopen(OpusFileCallbacks *_cb,const char *_path,const char *_mode,
_ogg_free(wpath);
}
#endif
if(fp!=NULL)*_cb=*&OP_FILE_CALLBACKS;
if(fp!=NULL)*_cb=*op_get_file_callbacks(fp);
return fp;
}

Expand Down Expand Up @@ -322,8 +373,8 @@ static int op_mem_seek(void *_stream,opus_int64 _offset,int _whence){
size=stream->size;
OP_ASSERT(size>=0);
/*Check for overflow:*/
if(_offset>size||_offset<size-OP_MEM_DIFF_MAX)return -1;
pos=(ptrdiff_t)(size-_offset);
if(_offset<-size||_offset>OP_MEM_DIFF_MAX-size)return -1;
pos=(ptrdiff_t)(size+_offset);
}break;
default:return -1;
}
Expand Down

0 comments on commit 2fccf8e

Please sign in to comment.