From 28e5de47840dc6b9a6fd330c6fa6ca8659ae84fa Mon Sep 17 00:00:00 2001 From: "sanyin.ljh" Date: Fri, 24 Oct 2025 13:59:05 +0800 Subject: [PATCH 1/2] Fix File::Read, File::ReadRange and bump_fuzz_seed.py * Add buf.UnsafeAdvance() before writing to buf in File::Read & ReadRange, to let buf has the correct size. * Use shutil.move(tmp.name, CFG) in bump_fuzz_seed.py to avoid possible error: Invalid cross-device link --- scripts/bump_fuzz_seed.py | 3 ++- src/cor/lyt/buf.cpp | 1 + src/io/file.cpp | 2 ++ test/src/quick_fuzz_tests/fuzz_config.json | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/bump_fuzz_seed.py b/scripts/bump_fuzz_seed.py index 47d0c201..73f119b1 100644 --- a/scripts/bump_fuzz_seed.py +++ b/scripts/bump_fuzz_seed.py @@ -13,6 +13,7 @@ from __future__ import annotations import json from pathlib import Path +import shutil import sys import tempfile @@ -34,7 +35,7 @@ def main() -> None: with tempfile.NamedTemporaryFile("w", delete=False) as tmp: json.dump(data, tmp, indent=2) tmp.write("\n") - Path(tmp.name).replace(CFG) + shutil.move(tmp.name, CFG) # Fix: Invalid cross-device link print(f"✅ base_seed bumped: {old} → {new}") diff --git a/src/cor/lyt/buf.cpp b/src/cor/lyt/buf.cpp index e5c2110c..0c954485 100644 --- a/src/cor/lyt/buf.cpp +++ b/src/cor/lyt/buf.cpp @@ -127,6 +127,7 @@ void Buf::Swap(const Buf& a_buf) { void Buf::UnsafeAdvance(const n_t byte_c) { /**/ FLS_ASSERT_CORRECT_N(byte_c); + FLS_ASSERT_LE(m_off + byte_c, m_capacity); m_off += byte_c; } diff --git a/src/io/file.cpp b/src/io/file.cpp index c4410f8e..893a4d91 100644 --- a/src/io/file.cpp +++ b/src/io/file.cpp @@ -49,6 +49,7 @@ void File::Read(Buf& buf) { auto file_size = fs::file_size(m_path); FLS_ASSERT_LE(file_size, buf.Capacity()) + buf.UnsafeAdvance(file_size); m_if_stream->read(reinterpret_cast(buf.mutable_data()), static_cast(file_size)); } @@ -61,6 +62,7 @@ void File::ReadRange(Buf& buf, const n_t offset, const n_t size) { [[maybe_unused]] auto file_size = fs::file_size(m_path); FLS_ASSERT_LE(offset + size, file_size); FLS_ASSERT_LE(size, buf.Capacity()); + buf.UnsafeAdvance(size); m_if_stream->seekg(static_cast(offset), std::ios::beg); m_if_stream->read(reinterpret_cast(buf.mutable_data()), static_cast(size)); diff --git a/test/src/quick_fuzz_tests/fuzz_config.json b/test/src/quick_fuzz_tests/fuzz_config.json index 889bc524..a9c7af5b 100644 --- a/test/src/quick_fuzz_tests/fuzz_config.json +++ b/test/src/quick_fuzz_tests/fuzz_config.json @@ -1,6 +1,6 @@ { "num_cases": 10, - "base_seed": 12, + "base_seed": 13, "delimiter": "|", "min_cols": 1, "max_cols": 2, From 554816c856bb24485d2663198c6dd5e1525bf8c2 Mon Sep 17 00:00:00 2001 From: "sanyin.ljh" Date: Fri, 24 Oct 2025 16:24:06 +0800 Subject: [PATCH 2/2] fix code format --- src/cor/lyt/buf.cpp | 2 +- src/io/file.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cor/lyt/buf.cpp b/src/cor/lyt/buf.cpp index 0c954485..c1355488 100644 --- a/src/cor/lyt/buf.cpp +++ b/src/cor/lyt/buf.cpp @@ -127,7 +127,7 @@ void Buf::Swap(const Buf& a_buf) { void Buf::UnsafeAdvance(const n_t byte_c) { /**/ FLS_ASSERT_CORRECT_N(byte_c); - FLS_ASSERT_LE(m_off + byte_c, m_capacity); + FLS_ASSERT_LE(m_off + byte_c, m_capacity); m_off += byte_c; } diff --git a/src/io/file.cpp b/src/io/file.cpp index 893a4d91..1a3e90c6 100644 --- a/src/io/file.cpp +++ b/src/io/file.cpp @@ -48,8 +48,8 @@ void File::Read(Buf& buf) { } auto file_size = fs::file_size(m_path); - FLS_ASSERT_LE(file_size, buf.Capacity()) - buf.UnsafeAdvance(file_size); + FLS_ASSERT_LE(file_size, buf.Capacity()); + buf.UnsafeAdvance(file_size); m_if_stream->read(reinterpret_cast(buf.mutable_data()), static_cast(file_size)); } @@ -62,7 +62,7 @@ void File::ReadRange(Buf& buf, const n_t offset, const n_t size) { [[maybe_unused]] auto file_size = fs::file_size(m_path); FLS_ASSERT_LE(offset + size, file_size); FLS_ASSERT_LE(size, buf.Capacity()); - buf.UnsafeAdvance(size); + buf.UnsafeAdvance(size); m_if_stream->seekg(static_cast(offset), std::ios::beg); m_if_stream->read(reinterpret_cast(buf.mutable_data()), static_cast(size));