fix: harden S4 audio verification
This commit is contained in:
@@ -69,13 +69,59 @@ func _find_first_audio_file(kind: String, name: String) -> String:
|
||||
directory.list_dir_begin()
|
||||
var entry := directory.get_next()
|
||||
while not entry.is_empty():
|
||||
if not directory.current_is_dir() and entry.get_extension().to_lower() in ADMITTED_EXTENSIONS:
|
||||
var path := directory_path.path_join(entry)
|
||||
if not directory.current_is_dir() and _is_loadable_external_audio(path):
|
||||
directory.list_dir_end()
|
||||
return directory_path.path_join(entry)
|
||||
return path
|
||||
entry = directory.get_next()
|
||||
directory.list_dir_end()
|
||||
return ""
|
||||
|
||||
func _is_loadable_external_audio(path: String) -> bool:
|
||||
var extension := path.get_extension().to_lower()
|
||||
if not extension in ADMITTED_EXTENSIONS:
|
||||
return false
|
||||
# Do not call Godot's external loaders unless the bytes identify a codec they load.
|
||||
# Other contract-admitted extensions (flac/m4a) intentionally have no native loader.
|
||||
match extension:
|
||||
"wav":
|
||||
return _has_wav_signature(path)
|
||||
"ogg", "oga", "opus":
|
||||
return _has_prefix(path, PackedByteArray([79, 103, 103, 83])) # OggS
|
||||
"mp3":
|
||||
return _has_mp3_signature(path)
|
||||
_:
|
||||
return false
|
||||
|
||||
func _has_wav_signature(path: String) -> bool:
|
||||
var file := FileAccess.open(path, FileAccess.READ)
|
||||
if file == null:
|
||||
return false
|
||||
var header := file.get_buffer(12)
|
||||
file.close()
|
||||
return header.size() == 12 and header.slice(0, 4) == PackedByteArray([82, 73, 70, 70]) and header.slice(8, 12) == PackedByteArray([87, 65, 86, 69]) # RIFF....WAVE
|
||||
|
||||
func _has_prefix(path: String, prefix: PackedByteArray) -> bool:
|
||||
var file := FileAccess.open(path, FileAccess.READ)
|
||||
if file == null:
|
||||
return false
|
||||
var header := file.get_buffer(prefix.size())
|
||||
file.close()
|
||||
return header == prefix
|
||||
|
||||
func _has_mp3_signature(path: String) -> bool:
|
||||
var file := FileAccess.open(path, FileAccess.READ)
|
||||
if file == null:
|
||||
return false
|
||||
var header := file.get_buffer(3)
|
||||
file.close()
|
||||
if header.size() < 2:
|
||||
return false
|
||||
if header.size() == 3 and header == PackedByteArray([73, 68, 51]): # ID3
|
||||
return true
|
||||
# MPEG frame sync: 11 set bits, MPEG version not reserved, layer not reserved.
|
||||
return header[0] == 255 and (header[1] & 0xE0) == 0xE0 and (header[1] & 0x18) != 0x08 and (header[1] & 0x06) != 0
|
||||
|
||||
func _play_ambience(path: String) -> void:
|
||||
var stream := _load_audio_stream(path)
|
||||
if stream == null or _ambience_player == null:
|
||||
|
||||
+12
-1
@@ -5,4 +5,15 @@ if [[ ! -x "$GODOT_BIN" ]]; then
|
||||
GODOT_BIN="$(command -v godot4 || command -v godot || true)"
|
||||
fi
|
||||
: "${GODOT_BIN:?Set GODOT_BIN or install godot4/godot}"
|
||||
exec "$GODOT_BIN" --headless --path . -s res://addons/gut/gut_cmdln.gd -gdir=res://tests/e2e -gexit
|
||||
|
||||
log_path="$(mktemp)"
|
||||
trap 'rm -f "$log_path"' EXIT
|
||||
set +e
|
||||
"$GODOT_BIN" --headless --path . -s res://addons/gut/gut_cmdln.gd -gdir=res://tests/e2e -gexit 2>&1 | tee "$log_path"
|
||||
godot_status=${PIPESTATUS[0]}
|
||||
set -e
|
||||
if grep -Eq 'SCRIPT ERROR|Parse Error' "$log_path"; then
|
||||
echo "E2E tests failed: Godot reported a script or parse error" >&2
|
||||
exit 1
|
||||
fi
|
||||
exit "$godot_status"
|
||||
|
||||
+12
-1
@@ -5,4 +5,15 @@ if [[ ! -x "$GODOT_BIN" ]]; then
|
||||
GODOT_BIN="$(command -v godot4 || command -v godot || true)"
|
||||
fi
|
||||
: "${GODOT_BIN:?Set GODOT_BIN or install godot4/godot}"
|
||||
exec "$GODOT_BIN" --headless --path . -s res://addons/gut/gut_cmdln.gd -gdir=res://tests/unit -gexit
|
||||
|
||||
log_path="$(mktemp)"
|
||||
trap 'rm -f "$log_path"' EXIT
|
||||
set +e
|
||||
"$GODOT_BIN" --headless --path . -s res://addons/gut/gut_cmdln.gd -gdir=res://tests/unit -gexit 2>&1 | tee "$log_path"
|
||||
godot_status=${PIPESTATUS[0]}
|
||||
set -e
|
||||
if grep -Eq 'SCRIPT ERROR|Parse Error' "$log_path"; then
|
||||
echo "unit tests failed: Godot reported a script or parse error" >&2
|
||||
exit 1
|
||||
fi
|
||||
exit "$godot_status"
|
||||
|
||||
Reference in New Issue
Block a user