diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp index 30fe310b33c..da313492897 100644 --- a/core/io/file_access_compressed.cpp +++ b/core/io/file_access_compressed.cpp @@ -283,7 +283,7 @@ uint64_t FileAccessCompressed::get_buffer(uint8_t *p_dst, uint64_t p_length) con if (dst_idx + 1 < p_length) { read_eof = true; } - return dst_idx + 1; + return dst_idx; } // Read the next block of compressed data. diff --git a/tests/core/io/test_file_access.h b/tests/core/io/test_file_access.h index 9ddbb7ead69..95debc19073 100644 --- a/tests/core/io/test_file_access.h +++ b/tests/core/io/test_file_access.h @@ -196,6 +196,28 @@ TEST_CASE("[FileAccess] Get/Store floating point half precision values") { DirAccess::remove_file_or_error(file_path_new); } + + SUBCASE("4096 bytes fastlz compressed") { + const String file_path = TestUtils::get_data_path("exactly_4096_bytes_fastlz.bin"); + + Ref f = FileAccess::open_compressed(file_path, FileAccess::READ, FileAccess::COMPRESSION_FASTLZ); + const Vector full_data = f->get_buffer(4096 * 2); + CHECK(full_data.size() == 4096); + CHECK(f->eof_reached()); + + // Data should be empty. + PackedByteArray reference; + reference.resize_zeroed(4096); + CHECK(reference == full_data); + + f->seek(0); + const Vector partial_data = f->get_buffer(4095); + CHECK(partial_data.size() == 4095); + CHECK(!f->eof_reached()); + + reference.resize_zeroed(4095); + CHECK(reference == partial_data); + } } } // namespace TestFileAccess diff --git a/tests/data/exactly_4096_bytes_fastlz.bin b/tests/data/exactly_4096_bytes_fastlz.bin new file mode 100644 index 00000000000..0915408d11e Binary files /dev/null and b/tests/data/exactly_4096_bytes_fastlz.bin differ