blueskythlikesclouds / MikuMikuLibrary

Format library and file editor for Hatsune Miku: Project DIVA games
MIT License
195 stars 45 forks source link

'EndOfStreamException: Unable to read beyond the end of the stream' when importing Virtua Fighter 5 models #31

Closed cnopt closed 11 months ago

cnopt commented 3 years ago

hello, I'm getting an EndOfStreamException when importing vanilla VF5 .farc files. The exception occurs when opening virtually every .farc file. However, for Virtua Fighter 5 Final Showdown files the program works flawlessly.

I've compiled the program myself and the exception is thrown at line 285 in EndianBinaryReader.cs, where ReadInt32 is overridden:

SwapBytes ? EndiannessHelper.Swap( base.ReadInt32() ) : base.ReadInt32();

And here's the full stack trace:

   at System.IO.__Error.EndOfFile()
   at System.IO.BinaryReader.FillBuffer(Int32 numBytes)
   at System.IO.BinaryReader.ReadInt32()
   at MikuMikuLibrary.IO.Common.EndianBinaryReader.ReadInt32() in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuLibrary\IO\Common\EndianBinaryReader.cs:line 286
   at MikuMikuLibrary.Textures.SubTexture.Read(EndianBinaryReader reader) in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuLibrary\Textures\SubTexture.cs:line 16
   at MikuMikuLibrary.Textures.SubTexture..ctor(EndianBinaryReader reader) in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuLibrary\Textures\SubTexture.cs:line 43
   at MikuMikuLibrary.Textures.Texture.<>c__DisplayClass31_2.<Read>b__0() in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuLibrary\Textures\Texture.cs:line 64
   at MikuMikuLibrary.IO.Common.EndianBinaryReader.ReadOffset(Action action) in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuLibrary\IO\Common\EndianBinaryReader.cs:line 161
   at MikuMikuLibrary.Textures.Texture.Read(EndianBinaryReader reader) in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuLibrary\Textures\Texture.cs:line 64
   at MikuMikuLibrary.Textures.Texture..ctor(EndianBinaryReader reader) in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuLibrary\Textures\Texture.cs:line 104
   at MikuMikuLibrary.Textures.TextureSet.<>c__DisplayClass5_0.<Read>b__0() in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuLibrary\Textures\TextureSet.cs:line 40
   at MikuMikuLibrary.IO.Common.EndianBinaryReader.ReadOffset(Action action) in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuLibrary\IO\Common\EndianBinaryReader.cs:line 161
   at MikuMikuLibrary.Textures.TextureSet.Read(EndianBinaryReader reader, ISection section) in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuLibrary\Textures\TextureSet.cs:line 40
   at MikuMikuLibrary.IO.BinaryFile.<Load>g__ReadClassic|12_1(<>c__DisplayClass12_0& ) in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuLibrary\IO\BinaryFile.cs:line 108
   at MikuMikuLibrary.IO.BinaryFile.Load(Stream source, Boolean leaveOpen) in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuLibrary\IO\BinaryFile.cs:line 32
   at MikuMikuModel.Nodes.IO.BinaryFileNode`1.Load(T data, Stream source) in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuModel\Nodes\IO\BinaryFileNode.cs:line 91
   at MikuMikuModel.Nodes.IO.BinaryFileNode`1.get_InternalData() in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuModel\Nodes\IO\BinaryFileNode.cs:line 34
   at MikuMikuModel.Nodes.Node`1.get_Data() in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuModel\Nodes\Node.cs:line 62
   at MikuMikuModel.Nodes.Textures.TextureSetNode.PopulateCore() in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuModel\Nodes\Textures\TextureSetNode.cs:line 186
   at MikuMikuModel.Nodes.Node`1.Populate() in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuModel\Nodes\Node.cs:line 178
   at MikuMikuModel.Nodes.Objects.ObjectSetNode.PopulateCore() in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuModel\Nodes\Objects\ObjectSetNode.cs:line 542
   at MikuMikuModel.Nodes.Node`1.Populate() in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuModel\Nodes\Node.cs:line 178
   at MikuMikuModel.Nodes.Wrappers.NodeAsTreeNode.Populate() in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuModel\Nodes\Wrappers\NodeAsTreeNode.cs:line 121
   at MikuMikuModel.Nodes.Wrappers.NodeTreeView.PopulateNode(NodeAsTreeNode node) in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuModel\Nodes\Wrappers\NodeTreeView.cs:line 26
   at MikuMikuModel.Nodes.Wrappers.NodeTreeView.OnAfterSelect(TreeViewEventArgs e) in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuModel\Nodes\Wrappers\NodeTreeView.cs:line 34
   at System.Windows.Forms.TreeView.TvnSelected(NMTREEVIEW* nmtv)
   at System.Windows.Forms.TreeView.WmNotify(Message& m)
   at System.Windows.Forms.TreeView.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)
   at System.Windows.Forms.Control.WmNotify(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.TreeView.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at System.Windows.Forms.Control.SendMessage(Int32 msg, Int32 wparam, IntPtr lparam)
   at System.Windows.Forms.TreeView.set_SelectedNode(TreeNode value)
   at MikuMikuModel.Nodes.Wrappers.NodeTreeView.set_SelectedNode(NodeAsTreeNode value) in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuModel\Nodes\Wrappers\NodeTreeView.cs:line 11
   at MikuMikuModel.GUI.Forms.MainForm.OpenFile(String filePath) in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuModel\GUI\Forms\MainForm.cs:line 188
   at MikuMikuModel.GUI.Forms.MainForm.OpenFile() in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuModel\GUI\Forms\MainForm.cs:line 220
   at MikuMikuModel.GUI.Forms.MainForm.OnOpen(Object sender, EventArgs e) in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuModel\GUI\Forms\MainForm.cs:line 226
   at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.WndProc(Message& m)
   at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at MikuMikuModel.Program.Main(String[] args) in D:\Users\Charlie\Documents\MikuMikuLibrary-2.0.3\MikuMikuModel\Program.cs:line 57

I know that VF5 isn't directly supported, but would be great to get this fixed

mrcloverthecoder commented 3 years ago

Not Skyth but remember that as you say, VF5 is not supported (at ALL).

But that's indeed really weird, since the engine is the same. Perhaps the file is corrupted/encrypted? It looks like the program is incorrectly reading the size of a file and reading past the file's end.