You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-13 13:31:48 +00:00
Add parameter checkes to FileAccess get_buffer functions
fix #46540
(cherry picked from commit cdf3099c68)
This commit is contained in:
committed by
Rémi Verschelde
parent
c7c7a0b822
commit
5a882a659a
@@ -302,9 +302,10 @@ uint8_t FileAccessCompressed::get_8() const {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const {
|
int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const {
|
||||||
|
ERR_FAIL_COND_V(!p_dst, -1);
|
||||||
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
|
ERR_FAIL_COND_V(p_length < 0, -1);
|
||||||
ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode.");
|
ERR_FAIL_COND_V_MSG(!f, -1, "File must be opened before use.");
|
||||||
|
ERR_FAIL_COND_V_MSG(writing, -1, "File has not been opened in read mode.");
|
||||||
|
|
||||||
if (at_end) {
|
if (at_end) {
|
||||||
read_eof = true;
|
read_eof = true;
|
||||||
|
|||||||
@@ -231,9 +231,11 @@ uint8_t FileAccessEncrypted::get_8() const {
|
|||||||
pos++;
|
pos++;
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const {
|
|
||||||
|
|
||||||
ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode.");
|
int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const {
|
||||||
|
ERR_FAIL_COND_V(!p_dst, -1);
|
||||||
|
ERR_FAIL_COND_V(p_length < 0, -1);
|
||||||
|
ERR_FAIL_COND_V_MSG(writing, -1, "File has not been opened in read mode.");
|
||||||
|
|
||||||
int to_copy = MIN(p_length, data.size() - pos);
|
int to_copy = MIN(p_length, data.size() - pos);
|
||||||
for (int i = 0; i < to_copy; i++) {
|
for (int i = 0; i < to_copy; i++) {
|
||||||
|
|||||||
@@ -150,7 +150,8 @@ uint8_t FileAccessMemory::get_8() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int FileAccessMemory::get_buffer(uint8_t *p_dst, int p_length) const {
|
int FileAccessMemory::get_buffer(uint8_t *p_dst, int p_length) const {
|
||||||
|
ERR_FAIL_COND_V(!p_dst, -1);
|
||||||
|
ERR_FAIL_COND_V(p_length < 0, -1);
|
||||||
ERR_FAIL_COND_V(!data, -1);
|
ERR_FAIL_COND_V(!data, -1);
|
||||||
|
|
||||||
int left = length - pos;
|
int left = length - pos;
|
||||||
|
|||||||
@@ -389,6 +389,8 @@ void FileAccessNetwork::_queue_page(int p_page) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
|
int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
|
||||||
|
ERR_FAIL_COND_V(!p_dst, -1);
|
||||||
|
ERR_FAIL_COND_V(p_length < 0, -1);
|
||||||
|
|
||||||
//bool eof=false;
|
//bool eof=false;
|
||||||
if (pos + p_length > total_size) {
|
if (pos + p_length > total_size) {
|
||||||
|
|||||||
@@ -284,6 +284,8 @@ uint8_t FileAccessPack::get_8() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int FileAccessPack::get_buffer(uint8_t *p_dst, int p_length) const {
|
int FileAccessPack::get_buffer(uint8_t *p_dst, int p_length) const {
|
||||||
|
ERR_FAIL_COND_V(!p_dst, -1);
|
||||||
|
ERR_FAIL_COND_V(p_length < 0, -1);
|
||||||
|
|
||||||
if (eof)
|
if (eof)
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -332,7 +332,8 @@ uint8_t FileAccessZip::get_8() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int FileAccessZip::get_buffer(uint8_t *p_dst, int p_length) const {
|
int FileAccessZip::get_buffer(uint8_t *p_dst, int p_length) const {
|
||||||
|
ERR_FAIL_COND_V(!p_dst, -1);
|
||||||
|
ERR_FAIL_COND_V(p_length < 0, -1);
|
||||||
ERR_FAIL_COND_V(!zfile, -1);
|
ERR_FAIL_COND_V(!zfile, -1);
|
||||||
at_eof = unzeof(zfile);
|
at_eof = unzeof(zfile);
|
||||||
if (at_eof)
|
if (at_eof)
|
||||||
|
|||||||
@@ -399,7 +399,8 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int FileAccess::get_buffer(uint8_t *p_dst, int p_length) const {
|
int FileAccess::get_buffer(uint8_t *p_dst, int p_length) const {
|
||||||
|
ERR_FAIL_COND_V(!p_dst, -1);
|
||||||
|
ERR_FAIL_COND_V(p_length < 0, -1);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (i = 0; i < p_length && !eof_reached(); i++)
|
for (i = 0; i < p_length && !eof_reached(); i++)
|
||||||
p_dst[i] = get_8();
|
p_dst[i] = get_8();
|
||||||
|
|||||||
@@ -248,7 +248,8 @@ uint8_t FileAccessUnix::get_8() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int FileAccessUnix::get_buffer(uint8_t *p_dst, int p_length) const {
|
int FileAccessUnix::get_buffer(uint8_t *p_dst, int p_length) const {
|
||||||
|
ERR_FAIL_COND_V(!p_dst, -1);
|
||||||
|
ERR_FAIL_COND_V(p_length < 0, -1);
|
||||||
ERR_FAIL_COND_V_MSG(!f, -1, "File must be opened before use.");
|
ERR_FAIL_COND_V_MSG(!f, -1, "File must be opened before use.");
|
||||||
int read = fread(p_dst, 1, p_length, f);
|
int read = fread(p_dst, 1, p_length, f);
|
||||||
check_errors();
|
check_errors();
|
||||||
|
|||||||
@@ -259,7 +259,8 @@ uint8_t FileAccessWindows::get_8() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int FileAccessWindows::get_buffer(uint8_t *p_dst, int p_length) const {
|
int FileAccessWindows::get_buffer(uint8_t *p_dst, int p_length) const {
|
||||||
|
ERR_FAIL_COND_V(!p_dst, -1);
|
||||||
|
ERR_FAIL_COND_V(p_length < 0, -1);
|
||||||
ERR_FAIL_COND_V(!f, -1);
|
ERR_FAIL_COND_V(!f, -1);
|
||||||
if (flags == READ_WRITE || flags == WRITE_READ) {
|
if (flags == READ_WRITE || flags == WRITE_READ) {
|
||||||
if (prev_op == WRITE) {
|
if (prev_op == WRITE) {
|
||||||
|
|||||||
@@ -125,6 +125,8 @@ uint8_t FileAccessAndroid::get_8() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int FileAccessAndroid::get_buffer(uint8_t *p_dst, int p_length) const {
|
int FileAccessAndroid::get_buffer(uint8_t *p_dst, int p_length) const {
|
||||||
|
ERR_FAIL_COND_V(!p_dst, -1);
|
||||||
|
ERR_FAIL_COND_V(p_length < 0, -1);
|
||||||
|
|
||||||
off_t r = AAsset_read(a, p_dst, p_length);
|
off_t r = AAsset_read(a, p_dst, p_length);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user