959 Commits

Author SHA1 Message Date
f25743b733 Merge pull request #45 from MSSonline/devel
fix: correct readableSectorTags allocation size to prevent heap overflow
2026-10-28 16:34:05 +00:00
Michael Stadelmann-Steinert
9672af54f0 Merge branch 'aaru-dps:devel' into devel 2026-10-28 16:41:25 +01:00
4fc9096623 Read Lead-In and Lead-Out sectors in aaruf_read_sector_long().
Sectors outside any track failed with AARUF_ERROR_TRACK_NOT_FOUND, so
converting an image silently dropped its Lead-Out sectors. Use the format of
the track after or before them, as they are written now, and return the ones
older images stored raw as they are.
2026-10-18 02:59:13 +01:00
728902ea7a Store Lead-In and Lead-Out sectors in the format of the track after and before them.
Sectors outside any track were stored raw as data, and negative sectors were
matched against tracks by their absolute address. Find the track by the signed
LBA and, following the Compact Disc specifications, give Lead-In sectors the
format of the first track and Lead-Out sectors that of the track before them.
2026-10-18 02:59:13 +01:00
2bf79531d1 Warn that aaruformattool is a development-only debugging tool. 2026-10-16 02:24:35 +01:00
06a22a171d Update documentation. 2026-10-13 15:30:23 +01:00
636c48ba31 Add tests for the in-house logger. 2026-10-13 15:25:15 +01:00
3fb285090e Document the in-house logger and AARU_ENABLE_LOGGING. 2026-10-13 15:25:15 +01:00
53465a8622 Remove the slog submodule.
Its upstream repository is gone, which broke recursive clones and
dependants fetching libaaruformat with submodules.
2026-10-13 15:25:15 +01:00
79a244c971 Replace slog with an in-house TRACE/FATAL logger.
The slog upstream repository no longer exists. The library only used
slog_trace/slog_fatal and slog_init, so a small internal logger in
src/log.c replaces it: printf-style, line-atomic output to stderr or to
the file named by AARUFORMAT_LOG_FILE, runtime filtering through
AARUFORMAT_LOG_LEVEL (trace, fatal, none), and lazy one-time
initialization that also covers aaruf_create().

The CMake option is now AARU_ENABLE_LOGGING; USE_SLOG remains as a
deprecated alias. log.h now includes inttypes.h, which several sources
relied on slog.h to provide for PRIu64.
2026-10-13 15:25:05 +01:00
0c64f87516 Remove unneeded scripts 2026-10-08 20:54:36 +01:00
bb385a20ba Bump version to v1.0.0-beta.2 v1.0.0-beta.2 2026-10-08 20:20:20 +01:00
64ba9346df Allow build script to build only macOS libraries. 2026-10-08 20:19:56 +01:00
ecf528da20 Fix cross platform build in macOS. 2026-10-08 20:17:42 +01:00
e358b1ca0e Update documentation. 2026-10-08 20:15:08 +01:00
d036b284ef Add a test recovering a damaged tracks block with erasure coding when opening 2026-10-08 18:52:10 +01:00
db2071258d Load the erasure coding map before processing the indexed blocks when opening, so damaged blocks can be recovered while processed 2026-10-08 18:52:10 +01:00
3af6a193d6 Free the erasure coding read state when closing images opened for reading, and the codec of resumed images when enabling erasure coding again 2026-10-08 18:52:10 +01:00
3fd0ce7ea3 Add a test recovering a damaged Data Position Measurement block with erasure coding 2026-10-08 18:30:20 +01:00
0941efe22c Recover a damaged Data Position Measurement block with erasure coding, once the erasure coding map is loaded 2026-10-08 18:30:20 +01:00
dd868ca249 Add the Data Position Measurement block to the 010 Editor and ImHex templates 2026-10-08 14:47:01 +01:00
db15c89cc5 [spec] Define the Data Position Measurement block 2026-10-08 14:46:43 +01:00
7d29ab3584 Add Data Position Measurement block tests 2026-10-08 14:45:59 +01:00
7b26941537 Add the Data Position Measurement block, with aaruf_get_dpm, aaruf_set_dpm and aaruf_clear_dpm, kept on resume and verified by its CRC 2026-10-08 14:45:59 +01:00
9c41f81e01 Bump version. 2026-10-03 13:48:09 +01:00
154075578b Set the cache free functions when creating an image
aaruf_create() left block_header_cache.free_func and block_cache.free_func at
the NULL the context was zeroed with, so on the write path every value the
caches evicted or dropped at close was leaked. aaruf_open() has always set
them; do the same here.
2026-09-02 00:04:05 +01:00
86e6b7ed82 Replace the existing value when caching a key that is already present
add_to_cache_uint64() called HASH_ADD without first looking the key up.
uthash keeps both entries in that case, but HASH_FIND only ever reaches the
newer one, so the older entry becomes unreachable and its value stays alive
until free_cache() tears the whole cache down. It also counted twice against
the cache budget.

ec_recover_data_block() reaches this: it caches the recovered BlockHeader for
a block offset that may already be in block_header_cache, because a header
read from the file is cached before the corruption check that sends the read
into erasure recovery.

Look the key up first, and on a hit free the old value and reuse the entry.
2026-09-02 00:03:52 +01:00
598d9224a7 Bound the block caches by bytes held instead of by entry count
The read caches sized themselves as MAX_CACHE_SIZE / (SectorSize << shift),
but ctx->shift is only ever assigned on the DDT v1 path, and the context is
zeroed at open. On every DDT v2 image the divisor therefore collapsed to the
sector size and the limit came out as 262144 entries, while each block_cache
entry holds a whole decompressed data block of SectorSize << dataShift bytes,
8 MiB with the default data_shift of 12. That is a ceiling of roughly 2 TiB
rather than the intended 512 MiB, so the count limit was never reached: a
sequential sector-by-sector pass cached the entire decompressed image and
freed none of it until aaruf_close(). Comparing two 40 GB images this way was
killed by the OOM reaper.

An entry count cannot express a memory budget when the values vary in size,
and here they vary by five orders of magnitude: block_header_cache holds
BlockHeader structs while block_cache holds megabyte payloads, yet both were
given the same limit. Track the byte size of each value instead and evict
least-recently-used entries until the cache is back under budget, and drop the
block geometry from cache initialization entirely. The block cache gets the
512 MiB MAX_CACHE_SIZE it always intended; block headers get a separate 8 MiB
budget, which covers far more blocks than the payload cache can hold.

The entry just inserted is never evicted, so callers may keep using the
pointer they handed over for the rest of the call. That also removes the
use-after-free that a zero limit used to cause: the old eviction loop started
at the hash head and could free the entry just added, after which the caller
read from freed memory.
2026-09-02 00:03:22 +01:00
c8de84871d Add repair-cd-arena tool command
Recovers CD sector prefix/suffix arenas in a v2 image whose resumed dump
sessions left the final deduplication table referencing slots past the
shrunken data block. Scans the file for every prefix/suffix generation,
rebuilds a fresh compact arena and DDT2 for the final table by sourcing
each custom slot from the generation that held it, and rewrites the index.
Supports --dry-run to report recoverable/lost slots without writing.
2026-09-01 14:56:21 +01:00
29bdba9c66 Add CD prefix/suffix resume and header-classification regression tests
Covers custom prefix/suffix bytes surviving a resumed dump session, a
resume that adds no new customs keeping the arena intact, and non-BCD
headers being stored verbatim rather than regenerated.
2026-09-01 14:56:13 +01:00
f3cf5f729c Report correct DDT status and encode NotDumped entries with the status shift
The Mode 1 user-data DDT entry was always written as Mode1Correct even
when the prefix or ECC/EDC was wrong; report Errored in that case like the
Mode 2 paths. The all-zero paths assigned SectorStatusNotDumped without
the <<60 status shift (harmless only because it is zero) and the Mode 2
all-zero path never marked its DDTs dirty, so an all-blank Mode 2 track
wrote no DDT at all; shift the status and set the dirty flags. Also widen
a truncating (uint32_t) cast on the Mode 2 prefix slot index to uint64_t.
2026-09-01 14:55:56 +01:00
03b2494fa6 Grow CD prefix/suffix arenas safely and zero unused slot bytes
The arenas were malloc'd and grown by doubling with realloc into the same
pointer: doubling could not grow a zero-length buffer, a failed realloc
leaked and lost the only pointer, and the Mode 2 Form 1/Form 2 paths left
part of each 288-byte slot uninitialized, writing heap garbage into the
image. Add a grow_arena() helper that grows before appending, keeps the
pointer on failure, and zeroes new capacity; allocate the arenas with
calloc and zero partial slots before copying.
2026-09-01 14:55:10 +01:00
e40922c5a0 Store CD headers that are non-BCD or on negative LBAs instead of regenerating
The write path decoded the MSF header with a naive nibble multiply and
compared against the positive sector address, so a header that was not
valid BCD but aliased the expected address (e.g. 0x1A vs 0x20) was
classified correct and silently rewritten as canonical BCD on read, and
lead-in (negative) sectors never matched. Validate BCD nibbles and range
via cd_header_matches_lba() using the signed LBA, and reconstruct the
prefix from the signed LBA on read.
2026-09-01 14:53:27 +01:00
21cc80f48a Bounds-check CD prefix/suffix arena reads and fix legacy over-reads
A DDT2 entry whose slot index points past the stored prefix/suffix block
(e.g. a resume-damaged or corrupt image) caused an out-of-bounds heap
read that was silently returned as sector data. Validate the pointer and
index against the arena length before copying, returning
AARUF_ERROR_CANNOT_READ_BLOCK with an Errored status instead. Also clamp
the two legacy Mode 2 fallback copies to the actual bare-sector length.
2026-09-01 14:52:45 +01:00
718c35c7a0 Restore CD sector prefix/suffix arena offsets when resuming a dump
On aaruf_open(resume_mode=true) the loaded prefix/suffix arena blocks had
their lengths recorded but the append offsets were left at zero, so a
resumed dump session re-appended custom sync/ECC bytes from offset 0,
overwriting existing slots and leaving the DDT2 pointing past the
rewritten (shrunken) block. Record the block length on load and set the
append offset to it on resume so new customs append after existing slots.
2026-09-01 14:51:17 +01:00
a9241a5fbd Bump version to 1.0.0-beta.1.1 in nuspec file 2026-09-01 13:07:46 +01:00
Michael Stadelmann-Steinert
3e85911a0b Update open.c
correct readableSectorTags allocation size to prevent heap overflow
2026-08-03 20:31:03 +02:00
Michael Stadelmann-Steinert
fb5eaa1246 Update create.c
correct readableSectorTags allocation size to prevent heap overflow
2026-08-03 20:28:26 +02:00
48dedd54d1 Merge branch 'devel' of https://github.com/aaru-dps/libaaruformat into devel 2026-07-31 08:58:18 +01:00
bbb0403e3d Fix double free: null metadata/cicm/json block pointers after error-path frees 2026-07-31 08:57:29 +01:00
105e07ac84 Merge pull request #44 from MSSonline/MSSonline-patch-1
Add missing PS5BD/UHDBD to OpticalDisc
2026-07-27 22:07:14 +01:00
Michael Stadelmann-Steinert
b42205440e Add missing PS5BD/UHDBD to mediatype OpticalDisc
## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] New filesystem, test images in [url]
- [ ] New media image, test images in [url]
- [ ] New partition scheme, test images in [url]
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [x] I have read the **CONTRIBUTING** document.
- [ ] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.

Add missing media types PS5BD and UHDBD to aaruf_get_xml_mediatype for optical discs.

Maybe the "xml" function should replaced by some generic meaning (e.g. aaruf_get_metadata_mediatype), since export is in .json file.
2026-07-27 21:45:13 +02:00
a95fea12ec Bump version v1.0.0-beta.1 2026-07-14 18:39:45 +01:00
6c05b4548e Merge pull request #43 from Cacodemon345/c-standard-fixes
Fixes to make it compile with `-Werror=strict-prototype`
2026-07-12 23:57:44 +01:00
78bc7faf0c Merge pull request #42 from Cacodemon345/patch-2
blake3.cmake: Match uppercase `CMAKE_SYSTEM_PROCESSOR` identifiers on AArch64
2026-07-12 23:56:59 +01:00
Cacodemon345
11d667ec9b Fixes to make it compile with -Werror=strict-prototype
Also ensures that some IDE warnings get ignored only on Clang
2026-07-13 02:45:17 +06:00
Cacodemon345
125392006a lzma.cmake: Match uppercase CMAKE_SYSTEM_PROCESSOR identifiers on AArch64 2026-07-12 13:54:32 +06:00
Cacodemon345
34404b532e blake3.cmake: Match uppercase CMAKE_SYSTEM_PROCESSOR identifiers 2026-07-12 13:41:13 +06:00
10e5f4d4a1 Add docker files 2026-07-11 14:12:45 +01:00
964e99cafd Add docker files 2026-07-11 14:11:54 +01:00