Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/libchdr_flac.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,17 @@ int flac_decoder_reset(flac_decoder* decoder, uint32_t sample_rate, uint8_t num_
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* +2A: start of stream data */
};
memcpy(decoder->custom_header, s_header_template, sizeof(s_header_template));
decoder->custom_header[0x08] = decoder->custom_header[0x0a] = (block_size*num_channels) >> 8;
decoder->custom_header[0x09] = decoder->custom_header[0x0b] = (block_size*num_channels) & 0xff;
/* STREAMINFO counts inter-channel samples, so the block size goes in as
* given - not multiplied by the channel count, which claimed twice the
* real maximum for stereo and made dr_flac allocate a decoded-sample
* buffer twice the size it needs. Over-declaring is otherwise harmless
* (the value only sizes that buffer and rejects frames larger than it),
* which is why this went unnoticed. The value is exact rather than
* merely safe: the encoder picks its block size with the same function
* the codecs here call to derive this argument. MAME's own decoder
* writes block_size too. */
decoder->custom_header[0x08] = decoder->custom_header[0x0a] = block_size >> 8;
decoder->custom_header[0x09] = decoder->custom_header[0x0b] = block_size & 0xff;
decoder->custom_header[0x12] = sample_rate >> 12;
decoder->custom_header[0x13] = sample_rate >> 4;
decoder->custom_header[0x14] = (sample_rate << 4) | ((num_channels - 1) << 1);
Expand Down
5 changes: 5 additions & 0 deletions tests/corpus/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ create_hd hd_lzma.chd -c lzma
create_hd hd_huff.chd -c huff
create_hd hd_zstd.chd -c zstd
create_hd hd_multi.chd -c zlib,lzma,huff,zstd
# The raw FLAC codec, on its own. hd_default happens to include flac hunks
# because that is one of chdman's default hard-disk codecs, but relying on a
# default to cover a codec is how a codec stops being covered - and the FLAC
# decoder holds the largest per-instance buffer of any codec here.
create_hd hd_flac.chd -c flac

# CD-ROM: default + per-codec.
create_cd cd_default.chd
Expand Down
2 changes: 2 additions & 0 deletions tests/rp2350-arm/check_budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
"hd_zstd": 200_000,
"hd_lzma": 80_000,
"hd_huff": 60_000,
"hd_flac": 100_000,
"cd_cdzl": 250_000,
"cd_cdzs": 400_000,
"cd_cdlz": 250_000,
"cd_cdfl": 250_000,
}

FAIL_RE = re.compile(r"^(\S+)\s+(?:OPEN|READ) FAILED: (.*)$")
Expand Down
4 changes: 4 additions & 0 deletions tests/rp2350-arm/fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
#include "embed/hd_zstd.h"
#include "embed/hd_lzma.h"
#include "embed/hd_huff.h"
#include "embed/hd_flac.h"
#include "embed/cd_cdzl.h"
#include "embed/cd_cdzs.h"
#include "embed/cd_cdlz.h"
#include "embed/cd_cdfl.h"

/* ---- malloc high-water-mark wrapper (linked via --wrap) ---- */

Expand Down Expand Up @@ -168,9 +170,11 @@ int main(void)
run_one("hd_zstd", hd_zstd_chd, hd_zstd_chd_len);
run_one("hd_lzma", hd_lzma_chd, hd_lzma_chd_len);
run_one("hd_huff", hd_huff_chd, hd_huff_chd_len);
run_one("hd_flac", hd_flac_chd, hd_flac_chd_len);
run_one("cd_cdzl", cd_cdzl_chd, cd_cdzl_chd_len);
run_one("cd_cdzs", cd_cdzs_chd, cd_cdzs_chd_len);
run_one("cd_cdlz", cd_cdlz_chd, cd_cdlz_chd_len);
run_one("cd_cdfl", cd_cdfl_chd, cd_cdfl_chd_len);
printf("=== done ===\n");
return 0;
}
6 changes: 4 additions & 2 deletions tests/rp2350-arm/gen_embed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ mkdir -p "$OUT_DIR"

# One representative CHD per decompressor the RAM-budget check cares about:
# every HD/raw codec (small hunks) plus every CD sub-codec (large hunks, the
# ones that pay for a subcode decompressor on top of the base one).
FILES=(hd_zlib hd_zstd hd_lzma hd_huff cd_cdzl cd_cdzs cd_cdlz)
# ones that pay for a subcode decompressor on top of the base one). FLAC is in
# the list because its decoder holds the largest per-instance buffer of any
# codec here - leaving it out is how an oversized allocation went unnoticed.
FILES=(hd_zlib hd_zstd hd_lzma hd_huff hd_flac cd_cdzl cd_cdzs cd_cdlz cd_cdfl)

for f in "${FILES[@]}"; do
src="$SEEDS_DIR/${f}.chd"
Expand Down
2 changes: 2 additions & 0 deletions tests/rp2350-riscv/check_budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
"hd_zstd": 200_000,
"hd_lzma": 80_000,
"hd_huff": 60_000,
"hd_flac": 100_000,
"cd_cdzl": 250_000,
"cd_cdzs": 400_000,
"cd_cdlz": 250_000,
"cd_cdfl": 250_000,
}

FAIL_RE = re.compile(r"^(\S+)\s+(?:OPEN|READ) FAILED: (.*)$")
Expand Down
4 changes: 4 additions & 0 deletions tests/rp2350-riscv/fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
#include "embed/hd_zstd.h"
#include "embed/hd_lzma.h"
#include "embed/hd_huff.h"
#include "embed/hd_flac.h"
#include "embed/cd_cdzl.h"
#include "embed/cd_cdzs.h"
#include "embed/cd_cdlz.h"
#include "embed/cd_cdfl.h"

/* ---- malloc high-water-mark wrapper (linked via --wrap) ---- */

Expand Down Expand Up @@ -169,9 +171,11 @@ int main(void)
run_one("hd_zstd", hd_zstd_chd, hd_zstd_chd_len);
run_one("hd_lzma", hd_lzma_chd, hd_lzma_chd_len);
run_one("hd_huff", hd_huff_chd, hd_huff_chd_len);
run_one("hd_flac", hd_flac_chd, hd_flac_chd_len);
run_one("cd_cdzl", cd_cdzl_chd, cd_cdzl_chd_len);
run_one("cd_cdzs", cd_cdzs_chd, cd_cdzs_chd_len);
run_one("cd_cdlz", cd_cdlz_chd, cd_cdlz_chd_len);
run_one("cd_cdfl", cd_cdfl_chd, cd_cdfl_chd_len);
printf("=== done ===\n");
return 0;
}
6 changes: 4 additions & 2 deletions tests/rp2350-riscv/gen_embed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ mkdir -p "$OUT_DIR"

# One representative CHD per decompressor the RAM-budget check cares about:
# every HD/raw codec (small hunks) plus every CD sub-codec (large hunks, the
# ones that pay for a subcode decompressor on top of the base one).
FILES=(hd_zlib hd_zstd hd_lzma hd_huff cd_cdzl cd_cdzs cd_cdlz)
# ones that pay for a subcode decompressor on top of the base one). FLAC is in
# the list because its decoder holds the largest per-instance buffer of any
# codec here - leaving it out is how an oversized allocation went unnoticed.
FILES=(hd_zlib hd_zstd hd_lzma hd_huff hd_flac cd_cdzl cd_cdzs cd_cdlz cd_cdfl)

for f in "${FILES[@]}"; do
src="$SEEDS_DIR/${f}.chd"
Expand Down
2 changes: 2 additions & 0 deletions tests/rv32/check_budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
"hd_zstd": 150_000,
"hd_lzma": 80_000,
"hd_huff": 200_000,
"hd_flac": 100_000,
"cd_cdzl": 200_000,
"cd_cdzs": 320_000,
"cd_cdlz": 200_000,
"cd_cdfl": 250_000,
}

FAIL_RE = re.compile(r"^(\S+)\s+(?:OPEN|READ) FAILED: (.*)$")
Expand Down
4 changes: 4 additions & 0 deletions tests/rv32/fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
#include "embed/hd_zstd.h"
#include "embed/hd_lzma.h"
#include "embed/hd_huff.h"
#include "embed/hd_flac.h"
#include "embed/cd_cdzl.h"
#include "embed/cd_cdzs.h"
#include "embed/cd_cdlz.h"
#include "embed/cd_cdfl.h"

/* ---- malloc high-water-mark wrapper (linked via --wrap) ---- */

Expand Down Expand Up @@ -165,9 +167,11 @@ int main(void)
run_one("hd_zstd", hd_zstd_chd, hd_zstd_chd_len);
run_one("hd_lzma", hd_lzma_chd, hd_lzma_chd_len);
run_one("hd_huff", hd_huff_chd, hd_huff_chd_len);
run_one("hd_flac", hd_flac_chd, hd_flac_chd_len);
run_one("cd_cdzl", cd_cdzl_chd, cd_cdzl_chd_len);
run_one("cd_cdzs", cd_cdzs_chd, cd_cdzs_chd_len);
run_one("cd_cdlz", cd_cdlz_chd, cd_cdlz_chd_len);
run_one("cd_cdfl", cd_cdfl_chd, cd_cdfl_chd_len);
printf("=== done ===\n");
return 0;
}
6 changes: 4 additions & 2 deletions tests/rv32/gen_embed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ mkdir -p "$OUT_DIR"

# One representative CHD per decompressor the RAM-budget check cares about:
# every HD/raw codec (small hunks) plus every CD sub-codec (large hunks, the
# ones that pay for a subcode decompressor on top of the base one).
FILES=(hd_zlib hd_zstd hd_lzma hd_huff cd_cdzl cd_cdzs cd_cdlz)
# ones that pay for a subcode decompressor on top of the base one). FLAC is in
# the list because its decoder holds the largest per-instance buffer of any
# codec here - leaving it out is how an oversized allocation went unnoticed.
FILES=(hd_zlib hd_zstd hd_lzma hd_huff hd_flac cd_cdzl cd_cdzs cd_cdlz cd_cdfl)

for f in "${FILES[@]}"; do
src="$SEEDS_DIR/${f}.chd"
Expand Down
Loading