Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flac.exe : 32bit overflow when using "--skip" on large raw input files > 4 GiB, garbage audio returned #655

Closed
SanLorenzo59 opened this issue Nov 7, 2023 · 1 comment · Fixed by #737

Comments

@SanLorenzo59
Copy link

I got garbage when encoding from a large raw audio file (> 7 GiB, 2 ch, 16 bit) and I tracked down this issue as a 32bit overflow.

See the output of a test case below:
--skip=1845437663 returns the same audio as
--skip=0771695839 .

1845437663-0771695839 is 2**30 which is equivalent to 4 GiB of raw audio data when using 32 bit per sample.

A self-made "FileCutter" written in C++ using long long 64bit aware counters gets what I want from the same large raw audio file.

I have seen this bug in flac-1.3.2-win and flac-1.4.3-win .

If this bug cannot be easily fixed then error action should be taken when --skip=<value> is above the limit.

G:\Music\Audacity\Joni Mitchell - Travelogue>regina
numeric digits 13; a=1845437663-0771695839 ; b=2**30 ; say a b a-b
^Z
1073741824 1073741824 0

G:\Music\Audacity\Joni Mitchell - Travelogue>

G:\Music\Audacity\Joni Mitchell - Travelogue>C:\tools\FLAC\flac-1.3.2-win\win64\flac.exe -f -o ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713a.BAD.flac"  --best --force-raw-format --endian=little --channels=2 --bps=16 --sample-rate=44100 --sign=signed  --skip=1845437663  --until=+21017806  ".\Joni Mitchell - Travelogue (5).raw"

G:\Music\Audacity\Joni Mitchell - Travelogue>C:\tools\FLAC\flac-1.3.2-win\win64\flac.exe -f -o ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713b.BAD.flac"  --best --force-raw-format --endian=little --channels=2 --bps=16 --sample-rate=44100 --sign=signed  --skip=0771695839  --until=+21017806  ".\Joni Mitchell - Travelogue (5).raw"

G:\Music\Audacity\Joni Mitchell - Travelogue>C:\tools\FLAC\flac-1.3.2-win\win64\flac.exe -d -f -o ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713a.BAD.raw" --force-raw-format --endian=little  --sign=signed   ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713a.BAD.flac"

G:\Music\Audacity\Joni Mitchell - Travelogue>C:\tools\FLAC\flac-1.3.2-win\win64\flac.exe -d -f -o ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713b.BAD.raw" --force-raw-format --endian=little  --sign=signed   ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713b.BAD.flac"

G:\Music\Audacity\Joni Mitchell - Travelogue>G:\Downloads\flac-1.4.3-win\flac-1.4.3-win\Win64\flac.exe -f -o ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713c.BAD.flac"  --best --force-raw-format --endian=little --channels=2 --bps=16 --sample-rate=44100 --sign=signed  --skip=1845437663  --until=+21017806  ".\Joni Mitchell - Travelogue (5).raw"

G:\Music\Audacity\Joni Mitchell - Travelogue>G:\Downloads\flac-1.4.3-win\flac-1.4.3-win\Win64\flac.exe -f -o ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713d.BAD.flac"  --best --force-raw-format --endian=little --channels=2 --bps=16 --sample-rate=44100 --sign=signed  --skip=0771695839  --until=+21017806  ".\Joni Mitchell - Travelogue (5).raw"

G:\Music\Audacity\Joni Mitchell - Travelogue>G:\Downloads\flac-1.4.3-win\flac-1.4.3-win\Win64\flac.exe -d -f -o ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713c.BAD.raw" --force-raw-format --endian=little  --sign=signed   ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713c.BAD.flac"

G:\Music\Audacity\Joni Mitchell - Travelogue>G:\Downloads\flac-1.4.3-win\flac-1.4.3-win\Win64\flac.exe -d -f -o ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713d.BAD.raw" --force-raw-format --endian=little  --sign=signed   ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713d.BAD.flac"

G:\Music\Audacity\Joni Mitchell - Travelogue>fc /b ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713a.BAD.flac" ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713b.BAD.flac"   | more
Comparing files .\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713a.BAD.flac and .\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713B.BAD.FLAC
FC: no differences encountered

G:\Music\Audacity\Joni Mitchell - Travelogue>fc /b ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713a.BAD.raw"  ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713b.BAD.raw"    | more
Comparing files .\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713a.BAD.raw and .\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713B.BAD.RAW
FC: no differences encountered

G:\Music\Audacity\Joni Mitchell - Travelogue>fc /b ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713c.BAD.flac" ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713d.BAD.flac"   | more
Comparing files .\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713c.BAD.flac and .\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713D.BAD.FLAC
FC: no differences encountered

G:\Music\Audacity\Joni Mitchell - Travelogue>fc /b ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713c.BAD.raw"  ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713d.BAD.raw"    | more
Comparing files .\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713c.BAD.raw and .\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713D.BAD.RAW
FC: no differences encountered

G:\Music\Audacity\Joni Mitchell - Travelogue>"C:\Program Files\Git\usr\bin\sha256sum.exe" ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713a.BAD.flac" ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713b.BAD.flac" ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713c.BAD.flac" ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713d.BAD.flac" ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713a.BAD.raw" ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713b.BAD.raw" ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713c.BAD.raw" ".\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713d.BAD.raw"
\80186417600636d67ca3d3979dcbccd8d6504d5df393f27ba85a8949a0efb47c *.\\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713a.BAD.flac
\80186417600636d67ca3d3979dcbccd8d6504d5df393f27ba85a8949a0efb47c *.\\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713b.BAD.flac
\cf75f3fde3cd60306d9f5ca8b7e362875ac4e475b3ddda7468f326b6110ba7c3 *.\\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713c.BAD.flac
\cf75f3fde3cd60306d9f5ca8b7e362875ac4e475b3ddda7468f326b6110ba7c3 *.\\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713d.BAD.flac
\5ae99ecfb2ee988bda4e183c49e6a06078af04a45262d759e0e127047182f4ba *.\\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713a.BAD.raw
\5ae99ecfb2ee988bda4e183c49e6a06078af04a45262d759e0e127047182f4ba *.\\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713b.BAD.raw
\5ae99ecfb2ee988bda4e183c49e6a06078af04a45262d759e0e127047182f4ba *.\\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713c.BAD.raw
\5ae99ecfb2ee988bda4e183c49e6a06078af04a45262d759e0e127047182f4ba *.\\__7-56-26206_0020961784_3E2A3C48_0015_0001845459713d.BAD.raw
@ktmf01
Copy link
Collaborator

ktmf01 commented Aug 29, 2024

I just looked into this, the cause is this line:

uint32_t skip_bytes = encoder_session.info.bytes_per_wide_sample * (uint32_t)skip;

All handling before and after that is 64-bit, but this is 32-bit for some reason. It seems like an easy fix, I'll come up with one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants