Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

String length limitations?

Rank

Total Posts: 25

Joined 2016-08-16

PM

I'm trying to find any limitations on the lengths of strings in a FIT file. The limit appears to be 255 characters per record for all strings in a record though I cannot find any documentation to back this up other than the source code.

Unfortunately a simple modification of the encode.cpp example leads me to believe that the string length limit is much lower:

std::wstring wstring_name(L"TestUser Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.");

userProfileMesg.SetFriendlyName(wstring_name); 


This change results in a runtime exception on WIndows 8.1.

I built encode.exe using Visual Studio 2013 and I get a runtime exception in userProfileMesg.SetFriendlyName. The call stack looks like:
msvcp120d.dll!6b05cee6() Unknown
  [Frames below may be incorrect 
and/or missingno symbols loaded for msvcp120d.dll] 
  [External Code] 
  encode
.exe!fit::FieldBase::SetSTRINGValue(const std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > & value, const unsigned char fieldArrayIndexLine 1045 C++
encode.exe!fit::Mesg::SetFieldSTRINGValue(const unsigned char fieldNum, const std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > & value, const unsigned char fieldArrayIndexLine 848 C++
  
encode.exe!fit::UserProfileMesg::SetFriendlyName(std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > friendlyNameLine 126 C++
  
encode.exe!EncodeSettingsFile() Line 116 C++
  
encode.exe!main() Line 207 C++
  
[External Code] 


void FieldBase::SetSTRINGValue(const FIT_WSTRINGvalue, const FIT_UINT8 fieldArrayIndex)
{
    
if (!IsValid())
        return;

    
Unicode::UTF8_STRING stringValue Unicode::Encode_BaseToUTF8(value);
    
FIT_UINT8 stringLength = (FIT_UINT8)stringValue.length();
    
FIT_UINT8 idx 0;
    
FIT_UINT8 nextIdx 0;
    
FIT_UINT8 numStrings = (FIT_UINT8)stringIndexes.size();
    
FIT_UINT8 dif 0;

    if ( 
fieldArrayIndex numStrings )
    
{
        idx 
stringIndexes[fieldArrayIndex];
        if (
fieldArrayIndex numStrings)
        
{
            nextIdx 
stringIndexes[fieldArrayIndex 1];
            
dif = (FIT_UINT8)( (value.length() + 1) - (nextIdx idx) );
            
values.erase(values.begin() + idxvalues.begin() + nextIdx);
        
}
        
else
        
{
            values
.erase(values.begin() + idxvalues.end());
        
}

        
for (auto i 0stringLength 1i++)
            
values.insert(values.begin() + idx i0);
    
}
    
else
    
{
        idx 
= (FIT_UINT8)values.size();
        
numStrings++;
        
stringIndexes.push_back(idx);
        for (
auto j 0stringLength 1j++)
        
{
            values
.push_back(0);
        
}
    }

    int i
;
    for (
0< (int)stringValue.length(); i++)
    
{
        values[idx 
i] static_cast<FIT_BYTE>(stringValue[i]);  // <<<<< exception thrown here
    
}

    values[idx 
i] 0// null terminate


is attempting to access fit::FieldBase::values[72] which is just beyond the end of the internal storage of the wstring values. There does not seem to be any wstring.reserve() calls. Also this loop is using stringValue.length() rather than the apparently correct stringLength.


     
RankRankRank

Total Posts: 68

Joined 0

PM

The SDK is not currently checking for potential overflow in the string length. The maximum length for a string is 254 bytes.      
Rank

Total Posts: 25

Joined 2016-08-16

PM

Ah I see, the length of the string pass to FieldBase::SetSTRINGValue is putting the length of the string into a FIT_UNIT8. So if you pass a string longer than 254 bytes long, the FIT SDK .cpp source will crash.

Will this bug be fixed?      
Rank

Total Posts: 2

Joined 2017-05-12

PM

I think that the maximum string length of 254 is AFTER it has been converted to UTF8. So, if you support unicode characters you will need to check the length of the UTF8 representation.