Note: Implementation of this function in WorldEdit.exe and storm.dll incorrectly treats the character as signed, which leads to the a buffer underflow if the character in the file name >= 0x80: The following steps happen when *pbKey == 0xBF and dwHashType == 0x0000 (calculating hash index) 1) Result of AsciiToUpperTable_Slash[*pbKey++] is sign-extended to 0xffffffbf 2) The "ch" is added to dwHash
| 247 | // with Korean characters in the name, cannot open the file back. |
| 248 | // |
| 249 | DWORD HashString(const char * szFileName, DWORD dwHashType) |
| 250 | { |
| 251 | LPBYTE pbKey = (BYTE *)szFileName; |
| 252 | DWORD dwSeed1 = 0x7FED7FED; |
| 253 | DWORD dwSeed2 = 0xEEEEEEEE; |
| 254 | DWORD ch; |
| 255 | |
| 256 | while(*pbKey != 0) |
| 257 | { |
| 258 | // Convert the input character to uppercase |
| 259 | // Convert slash (0x2F) to backslash (0x5C) |
| 260 | ch = AsciiToUpperTable[*pbKey++]; |
| 261 | |
| 262 | dwSeed1 = StormBuffer[dwHashType + ch] ^ (dwSeed1 + dwSeed2); |
| 263 | dwSeed2 = ch + dwSeed1 + dwSeed2 + (dwSeed2 << 5) + 3; |
| 264 | } |
| 265 | |
| 266 | return dwSeed1; |
| 267 | } |
| 268 | |
| 269 | DWORD HashStringSlash(const char * szFileName, DWORD dwHashType) |
| 270 | { |