Xuanwo opened a new pull request, #8918:
URL: https://github.com/apache/opendal/pull/8918
# Which issue does this PR close?
None. Found during maintenance; no separate issue was filed.
# Rationale for this change
Two correctness bugs existed in `opendal-service-sqlite`:
1. **Un-deletable root directory marker when `root = "/"`**:
`build_absolute_path("/", "/")` returns `""`. `SqliteBackend::create_dir`
unconditionally appended `/` when `p` did not end with `/`, inserting row `key
= '/'`, while `SqliteDeleter::delete_once("/")` deleted `key = ''`. Calling
`op.create_dir("/")` followed by `op.delete("/")` left an orphan `'/'` row
behind on `root = "/"`.
2. **Range-read TOCTOU race and 32-bit `SUBSTR` boundary issues**:
`SqliteReader::open` executed `get_length` in a first query and `get_range` in
a second query while discarding the atomic total length returned by
`get_range`. Under concurrent writes that shrink or replace the value between
the two queries, `RpRead` reported a stale `content_length` that mismatched the
returned bytes. In addition, passing offsets or lengths larger than `i32::MAX`
to SQLite `SUBSTR` truncates to signed 32-bit integers.
# What changes are included in this PR?
- `core/services/sqlite/src/backend.rs`:
- Keep empty `p` unchanged in `SqliteBackend::create_dir` (`""` for `root
= "/"`) so root marker keys match `stat` and `delete`.
- Add regression tests covering root `create_dir`/`stat`/`delete` on both
`root = "/"` and `root = "/sub/"`, forward and suffix range boundary cases
(including `i32::MAX`/`u64::MAX` offsets and lengths, empty values, multi-byte
UTF-8 text values, and missing keys), and concurrent range-read consistency
under shrinking/replacing writes.
- `core/services/sqlite/src/core.rs`:
- Update `SqliteCore::get_length` to return `Option<u64>`.
- Update `SqliteCore::get_range` to take `(offset: u64, limit:
Option<u64>)` and handle `offset >= i32::MAX` and `limit > i32::MAX` safely
without SQLite 32-bit `SUBSTR` truncation.
- Add `SqliteCore::get_suffix` to fetch suffix slices and atomic total
length in a single query.
- `core/services/sqlite/src/reader.rs`:
- Fetch ranged and suffix reads together with their atomic total length in
a single SQLite query and validate forward ranges against that atomic length
via `BytesRange::to_content_range`.
# Are there any user-facing changes?
- `op.create_dir("/")` followed by `op.delete("/")` with `root = "/"` now
removes the root directory marker row cleanly instead of leaving an orphan
`'/'` key in SQLite.
- Concurrent range reads on SQLite no longer return mismatched `RpRead`
content lengths and byte slices when a value changes during the read.
# Breaking changes
# AI Usage Statement
- Harness: pi
- Model: Gemini 4 Neon
- Effort: high
- Role: Investigated and reproduced both bugs against SQLite, implemented
the fixes and regression tests in `core/services/sqlite`, and verified unit and
behavior test suites. No open assumptions or unknowns remain.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]