Commit 4dbacd41 authored by npzacs's avatar npzacs
Browse files

Add file_size() with error detection

parent cf9c985b
......@@ -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 \
......
/*
* 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;
}
......@@ -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);
......
......@@ -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) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment