w00t-labs / libtorrent

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

Bitfield udefined behaviour leads to crash #633

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. In file_storage.hpp we see: "size_type symlink_index:16;"
2. size_type is typedef of "boost::int64_t" which is actually "long long".
3. Look at method file_storage::at in file_storage.cpp.
4. Line: if (ife.symlink_index >= 0) ret.symlink_path = symlink(ife);
is wrong because symlink_index is a bitfield. And according to C++ standart 
compiler make signed/unsigned decision itself for bitfields that aren't 
explicitly signed or unsigned.

http://en.cppreference.com/w/cpp/language/bit_field
(see notes below)

What is the expected output? What do you see instead?
I have crash, because in my case compiler made desicion that symlink_index 
should be unsigned.

What version of the product are you using? On what operating system?
libtorrent 16.10, but looks like 16.16 use same code. VS2012 update 4. Win7 x64.

I couldn't make symlink_index explicitly signed, so i just used workaround by 
adding condition to "if" statement. 

Sorry for my english =/

Original issue reported on code.google.com by d1ke...@gmail.com on 10 Jun 2014 at 11:08

GoogleCodeExporter commented 9 years ago
could you please confirm that this patch is reasonable and works?

http://dpaste.com/0CWW9DC/

Original comment by arvid.no...@gmail.com on 11 Jun 2014 at 1:21

GoogleCodeExporter commented 9 years ago
yes, this patch solves my problem

Original comment by d1ke...@gmail.com on 11 Jun 2014 at 7:52

GoogleCodeExporter commented 9 years ago
thanks! fixed in RC_0_16 and trunk.

Original comment by arvid.no...@gmail.com on 11 Jun 2014 at 8:37