Windows 10 2004 and later versions are hit by a bug that corrupts audio FLAC files as soon as their metadata is changed. Microsoft recognizes an issue with Windows File Explorer. Hotfix KB5003214 completely fixes the issue on affected PCs.
Windows 10 2004 and later users reported a strange bug that occurs with some FLAC files. After editing the metadata the files are corrupted – cannot be read in any program, including in VLC. The problem is related to a File Explorer bug. When the user is editing the metadata of a FLAC file, the program erroneously appends data before the first few bits that normally allow programs to recognize the file.
So when opening no program recognizes the presence of data structured according to the FLA formatC and suddenly the reading does not start and an error appears. Microsoft has identified the cause of the problem and released a hotfix KB5003214 which fixes, as a bonus, other bugs. If you have accidentally corrupted some FLAC files, you should also know that a trick is available. Microsoft has just published a PowerShell script that repairs corrupted files. Note, however, that the script does not repair the metadata.
Windows 10: How to Recover Corrupted Audio FLAC Files
To do this, it’s relatively simple:
- Open Notepad
- Copy and paste the following code:
# Copyright 2021 Microsoft
# This script will repair a FLAC file that has been corrupted by Media Foundation in reference to KB5003430.
# Refer to KB5003430 for further information
HelpMessage="The path to the FLAC file that has been corrupted by Media Foundation",
[ValidateScript( -not [String]::IsNullOrEmpty($_) -and (Test-Path $_) )]
# We need to back up the current file incase we have any errors
$FileDirectory = Split-Path -Resolve $File
$Filename = Split-Path -Leaf -Resolve $File
$FullPath = Join-Path -Resolve $FileDirectory $Filename
$Filename = [String]::Format("Backup_0:yyyyMMdd_hhmmss_1", [DateTime]::Now, $Filename)
$BackupLocation = Join-Path $FileDirectory $Filename
Write-Output "Microsoft FLAC Repair Tool. This tool will repair a FLAC audio file that was corrupted when editing its details."
Write-Output "Affected File: $FullPath"
Write-Output "A backup of the file will be made: $BackupLocation"
Write-Output "Do you wish to continue?"
$choice=$host.ui.PromptForChoice("Fixing FLAC Script", "Do you wish to continue", ('&Yes', '&No'), 1)
$blockType = $stream.ReadByte()
$lastBlock = ($blockType -shr 7) -ne 0
$blockType = $blockType -band 0x7F
if ($blockType -ne 0)
$blockSize = (($stream.ReadByte() -shl 16) -bor ($stream.ReadByte() -shl 8) -bor $stream.ReadByte())
if ($blockSize -lt 34)
$minAudioBlockSize = ($stream.ReadByte() -shl 8) -bor $stream.ReadByte()
$maxAudioBlockSize = ($stream.ReadByte() -shl 8) -bor $stream.ReadByte()
if ($minAudioBlockSize -lt 16 -or $maxAudioBlockSize -lt 16)
$minFrameSize = (($stream.ReadByte() -shl 16) -bor ($stream.ReadByte() -shl 8) -bor $stream.ReadByte())
$maxFrameSize = (($stream.ReadByte() -shl 16) -bor ($stream.ReadByte() -shl 8) -bor $stream.ReadByte())
$sampleInfo = (($stream.ReadByte() -shl 24) -bor ($stream.ReadByte() -shl 16) -bor ($stream.ReadByte() -shl 8) -bor $stream.ReadByte())
$sampleRate = $sampleInfo -shr 12
$channelCount = (($sampleInfo -shr 9) -band 0x7) + 1
$bitsPerSample = (($sampleInfo -shr 4) -band 0x1F) + 1
[UInt64]$sampleCount = (($stream.ReadByte() -shl 24) -bor ($stream.ReadByte() -shl 16) -bor ($stream.ReadByte() -shl 8) -bor $stream.ReadByte())
$sampleCount = (([UInt64]$sampleInfo -band 0xF) -shl 32) -bor $sampleCount
$MD5HashBytes = New-Object byte 16
$stream.Read($MD5HashBytes, 0, $MD5HashBytes.Length)
$MD5Hash = [Guid]($MD5HashBytes)
if ($sampleRate -eq 0)
# Passing these checks means that we likely have a stream info header and can rebuild the file
Write-Output "File Stream Information"
Write-Output "Sample Rate: $sampleRate"
Write-Output "Audio Channels: $channelCount"
Write-Output "Sample Depth: $bitsPerSample"
Write-Output "MD5 Audio Sample Hash: $MD5Hash"
if ($choice -eq 0)
Copy-Item $FullPath -Destination $BackupLocation -Force
$stream = [System.IO.File]::Open($FullPath, [System.IO.FileMode]::Open)
while ($stream.ReadByte() -eq 0)
# We now need to figure out where a valid FLAC metadata frame begins
# We are likely pointing to the last byte of the size member so we'll seek back 4 bytes and retry
$flacDataStartPosition = $stream.Position - 4
$flacDataStartPosition = $flacDataStartPosition + 1
# Insert the start code
if (Test-Path "$FullPath.tmp")
$fixedStream = [System.IO.File]::Open("$FullPath.tmp", [System.IO.FileMode]::CreateNew)
[byte]$startCode = [char]('f', 'L', 'a', 'C');
$fixedStream.Write($startCode, 0, $startCode.Length)
Move-Item -Force "$FullPath.tmp" $FullPath
- Save the file with the name “FixFlacFiles.ps1” checking that the document type is “text” in Type
- Find the file you saved and right click on it
- Click on Run with PowerShell
- When the script prompts you, enter the name of the corrupt FLAC file to repair it and press Entrance
Also read: Windows 10 – update KB5003214 bugged the taskbar, how to fix the problem
Have you been affected by the problem? Did the described method of making corrupted files playable again? Share your feedback in the comments of this article!