Windows 10竟会损坏用户文件?教你解决这个Bug

运维 系统运维
Flac音乐文件支持metadata,用户可以编辑metadata,让音乐文件带有艺术家、所属专辑、音轨等等信息。通常来说,metadata和音频数据并不相关,修改metadata并不会影响音频本身。但是,近日微软官方公布了Win10中存在一个Bug,在Win10中用资源管理器修改Flac文件的metadata,竟会导致音频的损坏!

如果你是一名音乐发烧友,那么应该知道Flac这种常见的无损音乐格式。Flac音乐文件支持metadata,用户可以编辑metadata,让音乐文件带有艺术家、所属专辑、音轨等等信息。通常来说,metadata和音频数据并不相关,修改metadata并不会影响音频本身。但是,近日微软官方公布了Win10中存在一个Bug,在Win10中用资源管理器修改Flac文件的metadata,竟会导致音频的损坏! 

 

根据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、复制以下字符,粘贴到记事本中: 

  1. # Copyright 2021 Microsoft 
  2.  
  3.  # This script will repair a FLAC file that has been corrupted by Media Foundation in reference to KB5003430. 
  4.  
  5.  # Refer to KB5003430 for further information 
  6.  
  7.  param( 
  8.  
  9.  [parameter(Mandatory=$true
  10.  
  11.  HelpMessage="The path to the FLAC file that has been corrupted by Media Foundation"
  12.  
  13.  ValueFromRemainingArguments=$true)] 
  14.  
  15.  [ValidateScript({ -not [String]::IsNullOrEmpty($_) -and (Test-Path $_) })] 
  16.  
  17.  [String]$File 
  18.  
  19.  ) 
  20.  
  21.  # We need to back up the current file incase we have any errors 
  22.  
  23.  $FileDirectory = Split-Path -Resolve $File 
  24.  
  25.  $Filename = Split-Path -Leaf -Resolve $File 
  26.  
  27.  $FullPath = Join-Path -Resolve $FileDirectory $Filename 
  28.  
  29.  $Filename = [String]::Format("Backup_{0:yyyyMMdd_hhmmss}_{1}", [DateTime]::Now, $Filename) 
  30.  
  31.  $BackupLocation = Join-Path $FileDirectory $Filename 
  32.  
  33.  Write-Output "Microsoft FLAC Repair Tool. This tool will repair a FLAC audio file that was corrupted when editing its details." 
  34.  
  35.  Write-Output "Affected File: $FullPath" 
  36.  
  37.  Write-Output "A backup of the file will be made: $BackupLocation" 
  38.  
  39.  Write-Output "Do you wish to continue?" 
  40.  
  41.  $choice=$host.ui.PromptForChoice("Fixing FLAC Script""Do you wish to continue", ('&Yes''&No'), 1) 
  42.  
  43.  function ParseStreamInfoMetadataBlock([System.IO.FileStream]$stream) 
  44.  
  45.  { 
  46.  
  47.  $blockType = $stream.ReadByte() 
  48.  
  49.  $lastBlock = ($blockType -shr 7) -ne 0 
  50.  
  51.  $blockType = $blockType -band 0x7F 
  52.  
  53.  if ($blockType -ne 0) 
  54.  
  55.  { 
  56.  
  57.  return $false 
  58.  
  59.  } 
  60.  
  61.  $blockSize = (($stream.ReadByte() -shl 16) -bor ($stream.ReadByte() -shl 8) -bor $stream.ReadByte()) 
  62.  
  63.  if ($blockSize -lt 34) 
  64.  
  65.  { 
  66.  
  67.  return $false 
  68.  
  69.  } 
  70.  
  71.  $minAudioBlockSize = ($stream.ReadByte() -shl 8) -bor $stream.ReadByte() 
  72.  
  73.  $maxAudioBlockSize = ($stream.ReadByte() -shl 8) -bor $stream.ReadByte() 
  74.  
  75.  if ($minAudioBlockSize -lt 16 -or $maxAudioBlockSize -lt 16) 
  76.  
  77.  { 
  78.  
  79.  return $false 
  80.  
  81.  } 
  82.  
  83.  $minFrameSize = (($stream.ReadByte() -shl 16) -bor ($stream.ReadByte() -shl 8) -bor $stream.ReadByte()) 
  84.  
  85.  $maxFrameSize = (($stream.ReadByte() -shl 16) -bor ($stream.ReadByte() -shl 8) -bor $stream.ReadByte()) 
  86.  
  87.  $sampleInfo = (($stream.ReadByte() -shl 24) -bor ($stream.ReadByte() -shl 16) -bor ($stream.ReadByte() -shl 8) -bor $stream.ReadByte()) 
  88.  
  89.  $sampleRate = $sampleInfo -shr 12 
  90.  
  91.  $channelCount = (($sampleInfo -shr 9) -band 0x7) + 1 
  92.  
  93.  $bitsPerSample = (($sampleInfo -shr 4) -band 0x1F) + 1 
  94.  
  95.  [UInt64]$sampleCount = (($stream.ReadByte() -shl 24) -bor ($stream.ReadByte() -shl 16) -bor ($stream.ReadByte() -shl 8) -bor $stream.ReadByte()) 
  96.  
  97.  $sampleCount = (([UInt64]$sampleInfo -band 0xF) -shl 32) -bor $sampleCount 
  98.  
  99.  $MD5HashBytes = New-Object byte[] 16 
  100.  
  101.  $stream.Read($MD5HashBytes, 0, $MD5HashBytes.Length) 
  102.  
  103.  $MD5Hash = [Guid]($MD5HashBytes) 
  104.  
  105.  if ($sampleRate -eq 0) 
  106.  
  107.  { 
  108.  
  109.  return $false 
  110.  
  111.  } 
  112.  
  113.  # Passing these checks means that we likely have a stream info header and can rebuild the file 
  114.  
  115.  Write-Output "File Stream Information" 
  116.  
  117.  Write-Output "Sample Rate: $sampleRate" 
  118.  
  119.  Write-Output "Audio Channels: $channelCount" 
  120.  
  121.  Write-Output "Sample Depth: $bitsPerSample" 
  122.  
  123.  Write-Output "MD5 Audio Sample Hash: $MD5Hash" 
  124.  
  125.  return $true 
  126.  
  127.  } 
  128.  
  129.  if ($choice -eq 0) 
  130.  
  131.  { 
  132.  
  133.  Copy-Item $FullPath -Destination $BackupLocation -Force 
  134.  
  135.  $stream = [System.IO.File]::Open($FullPath, [System.IO.FileMode]::Open
  136.  
  137.  $stream.Seek(4, [System.IO.SeekOrigin]::Begin
  138.  
  139.  while ($stream.ReadByte() -eq 0) {} 
  140.  
  141.  # We now need to figure out where a valid FLAC metadata frame begins 
  142.  
  143.  # We are likely pointing to the last byte of the size member so we'll seek back 4 bytes and retry 
  144.  
  145.  $flacDataStartPosition = $stream.Position - 4 
  146.  
  147.  $stream.Seek($flacDataStartPosition, [System.IO.SeekOrigin]::Begin
  148.  
  149.  while (-not(ParseStreamInfoMetadataBlock($stream))) 
  150.  
  151.  { 
  152.  
  153.  $flacDataStartPosition = $flacDataStartPosition + 1 
  154.  
  155.  $stream.Seek($flacDataStartPosition, [System.IO.SeekOrigin]::Begin
  156.  
  157.  } 
  158.  
  159.  # Insert the start code 
  160.  
  161.  $stream.Seek($flacDataStartPosition, [System.IO.SeekOrigin]::Begin
  162.  
  163.  if (Test-Path "$FullPath.tmp"
  164.  
  165.  { 
  166.  
  167.  Remove-Item "$FullPath.tmp" 
  168.  
  169.  } 
  170.  
  171.  $fixedStream = [System.IO.File]::Open("$FullPath.tmp", [System.IO.FileMode]::CreateNew) 
  172.  
  173.  [byte[]]$startCode = [char[]]('f''L''a''C'); 
  174.  
  175.  $fixedStream.Write($startCode, 0, $startCode.Length) 
  176.  
  177.  $stream.CopyTo($fixedStream) 
  178.  
  179.  $stream.Close() 
  180.  
  181.  $fixedStream.Close() 
  182.  
  183.  Move-Item -Force "$FullPath.tmp" $FullPath 
  184.  
  185.  } 

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

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

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

6、右键点击刚刚保存的脚本,然后选择“使用PowerShell运行”;

7、出现提示时,输入无法播放的Flac文件的文件名,然后按下回车键。

微软建议大家安装本月推送的可选累积更新,以避免修改Flac文件metadata出现的问题。

 

责任编辑:未丽燕 来源: PConline原创
相关推荐

2021-06-03 05:07:17

Windows10操作系统微软

2019-09-11 08:48:17

Windows 10WindowsBug

2020-05-06 19:16:45

Windows 10Windows微软

2021-06-02 16:31:16

微软Windows 10Windows

2021-01-31 07:42:26

Windows10操作系统微软

2020-02-05 09:53:03

Windows 10系统文件Windows

2019-03-04 11:30:07

修复Windows 10系统文件

2021-03-11 00:27:42

Windows 10Windows微软

2021-09-28 08:41:08

Windows 10操作系统微软

2021-09-29 08:44:19

Win10补丁漏洞

2018-07-09 08:35:45

Windows 10WindowsBug

2020-12-31 06:00:13

微软Windows 10Windows

2020-12-21 08:37:23

Windows10操作系统KB4592438

2021-06-02 08:02:34

Windows10操作系统微软

2018-08-16 10:15:41

修复Windows 10bootres.dll

2021-06-01 06:41:32

Windows10操作系统微软

2019-01-02 10:32:56

Linux系统文件运维

2020-12-24 05:53:55

Windows10操作系统21H2

2020-12-22 10:39:28

微软浏览器Windows

2018-05-30 14:29:14

WindowsWindows 10系统文件
点赞
收藏

51CTO技术栈公众号