libaacs | branch: master | npzacs <npz...@gmail.com> | Wed May 6 14:09:45 2015 +0300| [4dbacd41099f4d7803fda340f567fb38bb7a863f] | committer: npzacs
Add file_size() with error detection > http://git.videolan.org/gitweb.cgi/libaacs.git/?a=commit;h=4dbacd41099f4d7803fda340f567fb38bb7a863f --- Makefile.am | 1 + src/file/file.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/file/file.h | 2 +- src/libaacs/aacs.c | 9 ++++++--- 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index cd25143..7beb2e6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,6 +22,7 @@ libaacs_la_SOURCES=\ src/libaacs/mmc.c \ src/file/dirs.h \ src/file/file.h \ + src/file/file.c \ src/file/filesystem.h \ src/file/filesystem.c \ src/file/keydbcfg.c \ diff --git a/src/file/file.c b/src/file/file.c new file mode 100644 index 0000000..f94b592 --- /dev/null +++ b/src/file/file.c @@ -0,0 +1,41 @@ +/* + * This file is part of libbluray + * Copyright (C) 2014 VideoLAN + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include "file.h" + +#include <stdio.h> // SEEK_* + + +int64_t file_size(AACS_FILE_H *fp) +{ + int64_t pos = file_tell(fp); + int64_t res1 = file_seek(fp, 0, SEEK_END); + int64_t length = file_tell(fp); + int64_t res2 = file_seek(fp, pos, SEEK_SET); + + if (res1 < 0 || res2 < 0 || pos < 0 || length < 0) { + return -1; + } + + return length; +} diff --git a/src/file/file.h b/src/file/file.h index 5d1108f..95e0153 100644 --- a/src/file/file.h +++ b/src/file/file.h @@ -42,7 +42,7 @@ #define file_seek(X,Y,Z) X->seek(X,Y,Z) #define file_tell(X) X->tell(X) #define file_read(X,Y,Z) X->read(X,Y,Z) - +BD_PRIVATE int64_t file_size(AACS_FILE_H *fp); BD_PRIVATE extern AACS_FILE_H *(*file_open)(const char* filename, const char *mode); diff --git a/src/libaacs/aacs.c b/src/libaacs/aacs.c index 7865c4c..d5ea398 100644 --- a/src/libaacs/aacs.c +++ b/src/libaacs/aacs.c @@ -413,9 +413,12 @@ static size_t _read_file(AACS *aacs, const char *file, void **data) return 0; } - file_seek(fp, 0, SEEK_END); - f_size = file_tell(fp); - file_seek(fp, 0, SEEK_SET); + f_size = file_size(fp); + if (f_size <= 0) { + BD_DEBUG(DBG_AACS | DBG_CRIT, "Invalid size %"PRId64" for %s\n", file); + file_close(fp); + return 0; + } *data = malloc(f_size); if (*data) { _______________________________________________ libaacs-devel mailing list libaacs-devel@videolan.org https://mailman.videolan.org/listinfo/libaacs-devel