sasikalar / gamekit

Automatically exported from code.google.com/p/gamekit
0 stars 0 forks source link

FBT library, loading 32bit file on 64bit platfrom fails. #181

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When running the UnitFbtTests on Linux 64 bit on a amd64 platform the app 
crash. This is due to freeing a pointer that was not allocated.

The crash only happen in the tests using "be32bit.blend" (so when endian 
swapping is needed). However when running into Valgrind the crash does not 
occurs anymore (and no invalid frees is repported).

What Valgrinds detects are out of bound reads. This when loading any 32bit 
files (low and big endian).

Here is the valgrind trace:

Invalid read of size 8
  in fbtFile::link() in Tools/FileTools/File/fbtFile.cpp:644
  1: fbtFile::link() in <a href="file:///home/xavier/Projects/Gamekit/gamekit/Tools/FileTools/File/fbtFile.cpp:644" >Tools/FileTools/File/fbtFile.cpp:644</a>
  2: fbtFile::parseStreamImpl(fbtStream*) in <a href="file:///home/xavier/Projects/Gamekit/gamekit/Tools/FileTools/File/fbtFile.cpp:298" >Tools/FileTools/File/fbtFile.cpp:298</a>
  3: fbtFile::parse(char const*, int) in <a href="file:///home/xavier/Projects/Gamekit/gamekit/Tools/FileTools/File/fbtFile.cpp:145" >Tools/FileTools/File/fbtFile.cpp:145</a>
  4: parse_Ptr_PtrPtr_PtrArray(char const*, int&amp;, int&amp;) in <a href="file:///home/xavier/Projects/Gamekit/gamekit/UnitTests/FbtUnitTests/TestCase/testFbtBlendFile.cpp:33" >UnitTests/FbtUnitTests/TestCase/testFbtBlendFile.cpp:33</a>
  5: testFbtBlendFile_parsePointer32BitLinks_Test::TestBody() in <a href="file:///home/xavier/Projects/Gamekit/gamekit/UnitTests/FbtUnitTests/TestCase/testFbtBlendFile.cpp:115" >UnitTests/FbtUnitTests/TestCase/testFbtBlendFile.cpp:115</a>
  6: testing::Test::Run() in <a href="file:///home/xavier/Projects/Gamekit/gamekit/UnitTests/gtest-1.5.0/src/gtest.cc:2095" >UnitTests/gtest-1.5.0/src/gtest.cc:2095</a>
  7: testing::internal::TestInfoImpl::Run() in <a href="file:///home/xavier/Projects/Gamekit/gamekit/UnitTests/gtest-1.5.0/src/gtest.cc:2314" >UnitTests/gtest-1.5.0/src/gtest.cc:2314</a>
  8: testing::TestCase::Run() in <a href="file:///home/xavier/Projects/Gamekit/gamekit/UnitTests/gtest-1.5.0/src/gtest.cc:2420" >UnitTests/gtest-1.5.0/src/gtest.cc:2420</a>
  9: testing::internal::UnitTestImpl::RunAllTests() in <a href="file:///home/xavier/Projects/Gamekit/gamekit/UnitTests/gtest-1.5.0/src/gtest.cc:4024" >UnitTests/gtest-1.5.0/src/gtest.cc:4024</a>
  10: testing::UnitTest::Run() in <a href="file:///home/xavier/Projects/Gamekit/gamekit/UnitTests/gtest-1.5.0/src/gtest.cc:3687" >UnitTests/gtest-1.5.0/src/gtest.cc:3687</a>
  11: main in <a href="file:///home/xavier/Projects/Gamekit/gamekit/UnitTests/gtest-1.5.0/src/gtest_main.cc:38" >UnitTests/gtest-1.5.0/src/gtest_main.cc:38</a>
Address 0x676c6b0 is 144 bytes inside a block of size 148 alloc'd  1: malloc in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
  2: fbtFile::parseStreamImpl(fbtStream*) in <a href="file:///home/xavier/Projects/Gamekit/gamekit/Tools/FileTools/File/fbtFile.cpp:271" >Tools/FileTools/File/fbtFile.cpp:271</a>
  3: fbtFile::parse(char const*, int) in <a href="file:///home/xavier/Projects/Gamekit/gamekit/Tools/FileTools/File/fbtFile.cpp:145" >Tools/FileTools/File/fbtFile.cpp:145</a>
  4: parse_Ptr_PtrPtr_PtrArray(char const*, int&amp;, int&amp;) in <a href="file:///home/xavier/Projects/Gamekit/gamekit/UnitTests/FbtUnitTests/TestCase/testFbtBlendFile.cpp:33" >UnitTests/FbtUnitTests/TestCase/testFbtBlendFile.cpp:33</a>
  5: testFbtBlendFile_parsePointer32BitLinks_Test::TestBody() in <a href="file:///home/xavier/Projects/Gamekit/gamekit/UnitTests/FbtUnitTests/TestCase/testFbtBlendFile.cpp:115" >UnitTests/FbtUnitTests/TestCase/testFbtBlendFile.cpp:115</a>
  6: testing::Test::Run() in <a href="file:///home/xavier/Projects/Gamekit/gamekit/UnitTests/gtest-1.5.0/src/gtest.cc:2095" >UnitTests/gtest-1.5.0/src/gtest.cc:2095</a>
  7: testing::internal::TestInfoImpl::Run() in <a href="file:///home/xavier/Projects/Gamekit/gamekit/UnitTests/gtest-1.5.0/src/gtest.cc:2314" >UnitTests/gtest-1.5.0/src/gtest.cc:2314</a>
  8: testing::TestCase::Run() in <a href="file:///home/xavier/Projects/Gamekit/gamekit/UnitTests/gtest-1.5.0/src/gtest.cc:2420" >UnitTests/gtest-1.5.0/src/gtest.cc:2420</a>
  9: testing::internal::UnitTestImpl::RunAllTests() in <a href="file:///home/xavier/Projects/Gamekit/gamekit/UnitTests/gtest-1.5.0/src/gtest.cc:4024" >UnitTests/gtest-1.5.0/src/gtest.cc:4024</a>
  10: testing::UnitTest::Run() in <a href="file:///home/xavier/Projects/Gamekit/gamekit/UnitTests/gtest-1.5.0/src/gtest.cc:3687" >UnitTests/gtest-1.5.0/src/gtest.cc:3687</a>
  11: main in <a href="file:///home/xavier/Projects/Gamekit/gamekit/UnitTests/gtest-1.5.0/src/gtest_main.cc:38" >UnitTests/gtest-1.5.0/src/gtest_main.cc:38</a>

Original issue reported on code.google.com by xavier.thomas.1980@gmail.com on 20 Jul 2011 at 3:02

GoogleCodeExporter commented 9 years ago
One wierd thing that might be related:

The condition in fbtFile.cpp line 258 is never true:

if (chunk.m_code == SDNA)
{
    chunk.m_code = DNA1;
    stream->seek(-status, SEEK_CUR);
    chunk.m_len = stream->size() - stream->position();
}

void* curPtr = fbtMalloc(chunk.m_len);

Original comment by xavier.thomas.1980@gmail.com on 20 Jul 2011 at 3:15

GoogleCodeExporter commented 9 years ago
>The crash only happen in the tests using "be32bit.blend" 
Heap is corrupted in array member copy & swap.
It is fixed on r984.

Original comment by harkon...@gmail.com on 18 Aug 2011 at 6:13

GoogleCodeExporter commented 9 years ago
great thanks a lot.

Original comment by xavier.thomas.1980@gmail.com on 18 Aug 2011 at 9:47

GoogleCodeExporter commented 9 years ago
I was about to report this bug. 32 bit files crashes gamekit on 64 bit. It does 
work the other way around (re-saving the same file). Not sure if I used blender 
2.59 or 2.60 when it happened.

Original comment by kungfoobar@gmail.com on 9 Nov 2011 at 11:53

GoogleCodeExporter commented 9 years ago
So this issue is fixed and can be closed?

Original comment by erwin.coumans on 17 Nov 2011 at 12:07

GoogleCodeExporter commented 9 years ago
No, it still happens. Using Blender 2.60a, but I think it crashes with previous 
blender versions, too.

I've attached a (almost blank) 32 bit blend for testing. It crashes at 
gkBlendFile::readCurSceneInfo(Blender::Scene*).

Original comment by kungfoobar@gmail.com on 17 Nov 2011 at 6:57

Attachments:

GoogleCodeExporter commented 9 years ago
r984 by Harkon fixed the unit test crash but using kungfoobar blend file it 
still crashes.

Original comment by xavier.thomas.1980@gmail.com on 22 Jan 2012 at 4:31

GoogleCodeExporter commented 9 years ago
This is definitively a different bug than the first one.

The kungfoobar untitled.blend crash the Runtime (AppOgreKit) indeed but only 
when the runtime is compiled to use bParse, when using FileTools (FBT) it works 
OK.

Original comment by xavier.thomas.1980@gmail.com on 22 Jan 2012 at 4:48

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Oh I thought I was using FBT instead of bParse. Now I know why some changes I 
was doing were crashing.

What are the advantages of one versus the other?

(sorry for the double post)

Original comment by kungfoobar@gmail.com on 22 Jan 2012 at 5:09

GoogleCodeExporter commented 9 years ago
FBT code was written by Charlie (who wrote bParse wiht Erwin) as a replacement 
for bParse. with better code and easier way to implement your own file format 
with no need to use python scripts to update the format.It also has a GUI to 
explore/debug files.

In brief the FBT code is more "next-gen" and developer friendly but also much 
less tested than bParse.

I will close this bug as fixed. Please open another bug report with your test 
file and a better title.

Thanks.

Original comment by xavier.thomas.1980@gmail.com on 22 Jan 2012 at 5:41