ICU-8205 fix improper swap of uspoof, also add to swap test

X-SVN-Rev: 29139
This commit is contained in:
Steven R. Loomis 2010-12-02 19:17:46 +00:00
parent a30a0d2886
commit 96876653d9
3 changed files with 16 additions and 7 deletions

View File

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (C) 2008-2009, International Business Machines
* Copyright (C) 2008-2010, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*/
@ -942,17 +942,19 @@ uspoof_swap(const UDataSwapper *ds, const void *inData, int32_t length, void *ou
// Script Sets. The data is an array of int32_t
sectionStart = ds->readUInt32(spoofDH->fScriptSets);
sectionLength = ds->readUInt32(spoofDH->fScriptSetsLength) * 4;
sectionLength = ds->readUInt32(spoofDH->fScriptSetsLength) * sizeof(ScriptSet);
ds->swapArray32(ds, inBytes+sectionStart, sectionLength, outBytes+sectionStart, status);
// And, last, swap the header itself.
// int32_t fMagic // swap this
// uint8_t fFormatVersion[4] // Do not swap this
// int32_t all the rest // Swap the rest, all is 32 bit stuff.
// uint8_t fFormatVersion[4] // Do not swap this, just copy
// int32_t fLength and all the rest // Swap the rest, all is 32 bit stuff.
//
uint32_t magic = ds->readUInt32(spoofDH->fMagic);
ds->writeUInt32((uint32_t *)&outputDH->fMagic, magic);
ds->swapArray32(ds, &spoofDH->fLength, sizeof(SpoofDataHeader)-8, &outputDH->fLength, status);
uprv_memcpy(outputDH->fFormatVersion, spoofDH->fFormatVersion, sizeof(spoofDH->fFormatVersion));
// swap starting at fLength
ds->swapArray32(ds, &spoofDH->fLength, sizeof(SpoofDataHeader)-8 /* minus magic and fFormatVersion[4] */, &outputDH->fLength, status);
return totalSize;
}

View File

@ -1,6 +1,6 @@
/*
***************************************************************************
* Copyright (C) 2008-2009, International Business Machines Corporation
* Copyright (C) 2008-2010, International Business Machines Corporation
* and others. All Rights Reserved.
***************************************************************************
*
@ -22,6 +22,8 @@
#if !UCONFIG_NO_NORMALIZATION
#ifdef XP_CPLUSPLUS
U_NAMESPACE_BEGIN
// The maximium length (in UTF-16 UChars) of the skeleton replacement string resulting from
@ -331,7 +333,7 @@ class SpoofData: public UMemory {
//
//---------------------------------------------------------------------------------------
struct SpoofDataHeader {
int32_t fMagic; // (0x8345fdef)
int32_t fMagic; // (0x3845fdef)
uint8_t fFormatVersion[4]; // Data Format. Same as the value in struct UDataInfo
// if there is one associated with this data.
int32_t fLength; // Total lenght in bytes of this spoof data,
@ -395,6 +397,7 @@ struct SpoofDataHeader {
U_NAMESPACE_END
#endif /* XP_CPLUSPLUS */
/**
* Endianness swap function for binary spoof data.

View File

@ -55,6 +55,9 @@
#include "propname.h"
#include "rbbidata.h"
/* swapping implementation in i18n */
#include "uspoof_impl.h"
U_CAPI int32_t U_EXPORT2
unorm2_swap(const UDataSwapper *ds,
const void *inData, int32_t length, void *outData,
@ -1330,6 +1333,7 @@ static const struct {
#endif
#if !UCONFIG_NO_NORMALIZATION
{"nfc", "nrm", unorm2_swap},
{"confusables", "cfu", uspoof_swap},
#endif
{"unames", "icu", uchar_swapNames}
};