Win10 will damage user files!

   If you are a music enthusiast, you should know Flac, a common lossless music format. Flac music files support metadata, and users can edit metadata so that the music files contain information such as artist, album, audio track, and so on. Generally speaking, metadata and audio data are not related, and modifying metadata will not affect the audio itself. However, recently, Microsoft officially announced that there is a bug in Win10. Using Explorer to modify the metadata of the Flac file in Win10 will cause audio damage!

Windows 10 logo


  According to a report from Windows Latest, a supporting document released by Microsoft disclosed that if you use File Explorer to modify the metadata of Flac music files in Win10 version 2004 or later, Flac audio files will be lost. This bug appears in Win10 Professional Edition, Home Edition, Enterprise Edition, Workstation Edition and even other versions of Win10.

  According to the support file released by Microsoft earlier this month, Win10's file explorer caused this error. It destroyed the ID3 frame contained in the Flac file header, or metadata, and this ID3 frame is responsible for storing audio comments, such as music titles. , Artist, album, track number, etc. On Win10, the Flac processing program ignores the ID3 frame. The program thinks that the Flac file uses a 4-byte file header. When the Flac file is edited by Win10, the ID3 frame is overwritten, resulting in no start code. The music player cannot recognize the modified file.

  Therefore, in Win10, if you directly use the File Explorer to modify the metadata of the Flac music file's title, artist, etc., the file will not be played.

  Fortunately, Microsoft has determined the root cause of the bug, and users can upgrade the KB5003214 patch through Windows Update to fix it.

  In the KB5003214 patch, Microsoft confirmed that the above-mentioned error has been fixed. After modifying the metadata of Flac's title, artist, etc., Flac will no longer become unplayable. For the damaged Flac file, Microsoft has released a PowerShell script to repair it. After running the script, the Flac file can be played again, but the metadata information that has been lost from the ID3 framework cannot be recovered.

  The following is the specific method of using PowerShell script to repair Flac file.

  1. Open the notepad.

  2. Copy the following characters and paste them into Notepad:

  # 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

  param (

  [parameter(Mandatory=$true,

  HelpMessage="The path to the FLAC file that has been corrupted by Media Foundation",

  ValueFromRemainingArguments=$true)]

  [ValidateScript({ -not [String]:: IsNullOrEmpty($_) -and (Test-Path $_) })]

  [String]$File

  )

  # 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)

  function ParseStreamInfoMetadataBlock([System.IO.FileStream]$stream)

  {

  $blockType = $stream.ReadByte()

  $lastBlock = ($blockType -shr 7) -ne 0

  $blockType = $blockType -band 0x7F

  if ($blockType -ne 0)

  {

  return $false

  }

  $blockSize = (($stream.ReadByte() -shl 16) -bor ($stream.ReadByte() -shl 8) -bor $stream.ReadByte())

  if ($blockSize -lt 34)

  {

  return $false

  }

  $minAudioBlockSize = ($stream.ReadByte() -shl 8) -bor $stream.ReadByte()

  $maxAudioBlockSize = ($stream.ReadByte() -shl 8) -bor $stream.ReadByte()

  if ($minAudioBlockSize -lt 16 -or $maxAudioBlockSize -lt 16)

  {

  return $false

  }

  $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)

  {

  return $false

  }

  # 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"

  return $true

  }

  if ($choice -eq 0)

  {

  Copy-Item $FullPath -Destination $BackupLocation -Force

  $stream = [System.IO.File]::Open($FullPath, [System.IO.FileMode]::Open)

  $stream.Seek(4, [System.IO.SeekOrigin]::Begin)

  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

  $stream.Seek($flacDataStartPosition, [System.IO.SeekOrigin]::Begin)

  while (-not(ParseStreamInfoMetadataBlock($stream)))

  {

  $flacDataStartPosition = $flacDataStartPosition + 1

  $stream.Seek($flacDataStartPosition, [System.IO.SeekOrigin]::Begin)

  }

  # Insert the start code

  $stream.Seek($flacDataStartPosition, [System.IO.SeekOrigin]::Begin)

  if (Test-Path “$FullPath.tmp”)

  {

  Remove-Item “$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)

  $stream.CopyTo($fixedStream)

  $stream.Close()

  $fixedStream.Close()

  Move-Item -Force “$FullPath.tmp” $FullPath

  }

 



 Download Script Here 


  3. Save the file. In the "Save As" dialog box, locate the directory where you want to save the PowerShell script;

  4. In the file name input box, enter "FixFlacFiles.ps1" and change the type of save as file to Text Documents (*.txt);

  5. Enter the directory where you saved the PowerShell script;

  6. Right-click the script you just saved, and select "Run with PowerShell";

  7. When prompted, enter the file name of the Flac file that cannot be played, and then press the Enter key.

  Microsoft recommends that you install the optional cumulative update pushed this month to avoid problems with modifying the metadata of the Flac file.


Post a Comment

Previous Post Next Post