使用D2010,接收邮件时有时会发生range check error的错误,而foxmail则可以正常接收,估计是indy本身的bug,追踪了一下,发现错误出现在IdCoder3to4.pas中的第277行:
Result[LOutPos] := (FDecodeTable[LInBytes[0]] shl 2) or ((FDecodeTable[LInBytes[1]] shr 4) and 3);
抱着试试看的方式google了一下,在Embarcdero的论坛上竟然有人提这个bug了:
https://forums.embarcadero.com/message.jspa?messageID=192364
内容如下:
In \Protocols\IdCoder3to4.pas line 277
// Reduce to 3 bytes
Result[LOutPos] := (FDecodeTable[LInBytes[0]] shl 2) or ((FDecodeTable[LInBytes[1]] shr 4) and 3);
Result[LOutPos + 1] := ((FDecodeTable[LInBytes[1]] and 15) shl 4) or ((FDecodeTable[LInBytes[2]] shr 2) and 15);
Result[LOutPos + 2] := ((FDecodeTable[LInBytes[2]] and 3) shl 6) or (FDecodeTable[LInBytes[3]] and 63);
When the base64 data contains, for whatever reason, garbage (for instance
a space as first character) above code will generate a range-check error.
In case of a space FDecodeTable[LInBytes[0]] will return 255, which is
then "shifted" by two times add eax, eax.
Suggested change:
// Reduce to 3 bytes
Result[LOutPos] := ((FDecodeTable[LInBytes[0]] and 63) shl 2) or ((FDecodeTable[LInBytes[1]] shr 4) and 3);
...
Thanks, I have checked it in.
--
Remy Lebeau (TeamB)
可能在下个版本中能修正这个问题.