www.30abysses.com / TWY / 2016 / 11 / 21 / CS: C# `System.Valuetype.GetHashCode()` 潛在效能、安全問題


BALANCE and EQUILIBRIUM



CS: C# System.Valuetype.GetHashCode() 潛在效能、安全問題

ValueType 的 `GetHashCode() 預設實作是把所有欄位(field) 大鍋炒成 雜湊(hash)值;有看過些說法主張這可能造成潛在的效能問題外,然而,更嚴重的 是如其原碼註解 所指出的,這多少會在某種程度上把敏感資訊透露出去,也 就是有 潛在的安全問題

// The default implementation of GetHashCode() for all value types.
// Note that this implementation reveals the value of the fields.
// So if the value type contains any sensitive information it should
// implement its own GetHashCode().
FCIMPL1(INT32, ValueTypeHelper::GetHashCode, Object* objUNSAFE)

是故,原碼註解主張

若此 value type 含有敏感資訊,那它應該為 GetHashCode() 提供自己的實 作版本。

然而,很遺憾的, System.Valuetype.GetHashCode() 的官方文件 目前(2016-11-25)並沒有特別提醒這件事。



[ Contact us | facebook | hello@30abysses.com | 聯絡我們 ]


CS: C# `System.Valuetype.GetHashCode()` 潛在效能、安全問題 by TW Yang <twy@30abysses.com>
is licensed under a Creative Commons Attribution 4.0 International License (CC-BY-4.0).

Creative Commons License (CC-BY-4.0)