Win10竟会损坏用户文件!教你解决这个Bug

珠江路在线   2021年6月3日  【 转载 】 

  本文标签:Win10,Bug

  假如你是一名音乐玩家,那么应该晓得Flac这种常见的无损音乐 格局 。Flac音乐文件 支撑metadata,消费者 能够编辑metadata,让音乐文件带有艺术家、所属专辑、音轨等等信息 。通常来说,metadata和音频数据并不 有关, 批改metadata并不会影响音频 本身 。然而,近日微软官方公布了Win10中存在一个Bug,在Win10中用资源治理器 批改Flac文件的metadata,竟会招致音频的 败坏!

Win10竟会
败坏消费者文件!教你解决这个Bug

  依据Windows Latest的报导,微软最新公布的一份 支撑文件披露,假如在Win10的2004或者更高版本中, 使用文件资源治理器 批改Flac音乐文件的metadata,就会损耗Flac音频文件 。这个Bug在Win10专业版、家庭版、企业版、工作站版乃至 其余版本的Win10中均有浮现 。

  依据微软本月早些时候公布的 支撑文件,Win10的文件资源治理器招致了这个 舛误,它 毁坏了Flac文件头包括的ID3框架也便是metadata,而这个ID3框架负责存储音频的 诠释,例如音乐 题目、艺术家、专辑、曲目编号等 。在Win10上,Flac的 解决程序 忽视了ID3框架,该程序认为Flac文件在 使用4字节的文件头,当Flac文件被Win10编辑的时候,ID3框架被 遮蔽了,招致没有了开始代码,招致了音乐播放器 无奈 鉴别被 批改后的文件 。

   因而,在Win10中,假如你直接用文件资源治理器 批改Flac音乐文件的 题目、艺术家等metadata,会招致该文件 无奈播放 。

   厄运的是,微软已经确定了Bug的 根本缘由,消费者 能够通过Windows Update 晋级KB5003214补丁进行修复 。

  在KB5003214补丁中,微软确认了上文提到的 舛误已经被修复, 批改了Flac的 题目、艺术家等metadata后,Flac不会再变得 无奈播放 。而关于已经 败坏了的Flac文件,微软则公布了一个PowerShell脚 原来进行修复,运行该脚本后Flac文件即可再一次播放,不过已经从ID3框架中 迷失了的metadata信息并不能 复原 。

  下面是利用PowerShell脚本修复Flac文件的具体 步骤 。

  1、开启记事本;

  2、复制以下字符,粘贴到记事本中:

  # 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

  [UInt6?4]$sampleCount = (($stream.ReadByte() -shl 24) -bor ($stream.ReadByte() -shl 16) -bor ($stream.ReadByte() -shl 8) -bor $stream.ReadByte())

  $sampleCount = (([UInt6?4]$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

  }

  3、 保留文件,在“另存为”对话框中,将目录定位到你想要 保留PowerShell脚本的位置;

  4、在文件名输入框中,输入“FixFlacFiles.ps1”,将另存为文件的类型更改为Text Documents (* 。txt);

  5、进入到你 保留该PowerShell脚本的目录;

  6、右键点击方才 保留的脚本, 而后 取舍“ 使用PowerShell运行”;

  7、浮现 揭示时,输入 无奈播放的Flac文件的文件名, 而后按下回车键 。

  微软 提议大家安装本月推送的可选累积更新,以幸免 批改Flac文件metadata浮现的问题 。

免责声明:凡标注转载/编译字样内容并非本站原创,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。