加载地址 X 时,对于 Y 类型的对象没有足够的空间
Load of address X with insufficient space for an object of type Y
我正在通过未定义的行为清理器运行一些更新。消毒剂正在产生一条我不太明白的消息:
kalyna.cpp:1326:61: runtime error: load of address 0x0000016262c0 with insufficient space for an object of type 'const uint32_t'
0x0000016262c0: note: pointer points here
20 8b c1 1f a9 f7 f9 5c 53 c4 cf d2 2f 3f 52 be 84 ed 96 1b b8 7a b2 85 e0 96 7d 5d 70 ee 06 07
^
有问题的代码试图通过接触缓存行范围内的地址来使缓存计时攻击更加困难。1326 行是带有reinterpret_cast
的线路:
// In KalynaTab namespace
uint64_t S[4][256] = {
...
};
...
// In library's namespace
const int cacheLineSize = GetCacheLineSize();
volatile uint32_t _u = 0;
uint32_t u = _u;
for (unsigned int i=0; i<256; i+=cacheLineSize)
u &= *reinterpret_cast<const uint32_t*>(KalynaTab::S+i);
为什么桑提齐尔声称uint32_t u
没有足够的空间容纳uint32_t
?
或者,也许,我是否正确解析了错误消息?这是消毒员抱怨的吗?如果我解析不正确,那么消毒剂在抱怨什么?
$ lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
$ gcc --version
gcc (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1)
标识符S
不会转换为您认为的类型的指针。因此,指针算法使您远远超出了数据范围,最好通过示例来显示:
#include <iostream>
#include <cstdint>
uint64_t S[4][256];
int main()
{
std::cout << static_cast<void*>(S+0) << 'n';
std::cout << static_cast<void*>(S+1) << 'n';
std::cout << static_cast<void*>(S+2) << 'n';
std::cout << static_cast<void*>(S+3) << 'n';
std::cout << 'n';
std::cout << static_cast<void*>(*S+0) << 'n';
std::cout << static_cast<void*>(*S+1) << 'n';
std::cout << static_cast<void*>(*S+2) << 'n';
std::cout << static_cast<void*>(*S+3) << 'n';
}
输出(明显取决于平台)
0x1000020b0
0x1000028b0
0x1000030b0
0x1000038b0
0x1000020b0
0x1000020b8
0x1000020c0
0x1000020c8
请注意每个下行第一个数字序列的步幅0x800。这是有道理的,因为每行由0x100个条目组成,每个条目 8 个字节(uint64_t 元素)。指针算术中使用的指针类型为uint64_t (*)[256]
。
现在注意第二个序列的步伐,它只窥视S[0]
。步幅为 8 个字节,每个插槽一个。此计算中转换的指针的类型为uint64_t *
。
简而言之,您的指针算术假设S
转换为uint64_t*
,但事实并非如此。与所有数组到指针的转换一样,它转换为指向第一个元素的指针,包括相同类型。数组数组中的元素类型是uint64_t[256]
,所以转换后的指针类型是uint64_t (*)[256]
。
相关文章:
- 是否可以在专用内存空间中分配一个为提升管理共享内存而创建的对象
- C 对象和名称空间
- 当对象在屏幕空间中较小时,OpenGL 更新缓慢
- 由另一个对象重用对象的空间
- makefile对我的名称空间对象/函数/构造函数的不确定引用
- 加载地址 X 时,对于 Y 类型的对象没有足够的空间
- 将每个对象渲染到空间中,并在3D场景上渲染2D场景
- 声明方法时没有名称空间,也没有对C 作用的方法的对象
- 命名空间:不能在没有对象的情况下调用成员函数
- 命名空间、标头和对象的层次结构
- 由于命名空间而导致的对象实例化错误
- ITK中是否有表面构建函数,该函数返回一个容器管空间对象
- C++将类添加到命名空间以创建新的类对象
- 只有当声明一个对象时,内存空间才会分配给类的数据成员,那么为什么 Sizeof(class_name) 给我结果
- 我的3D OpenGL对象围绕世界来源,而不是本地空间来源.我在做什么错或误会
- 找出3D空间中两个对象的公式
- 其他命名空间中的对象没有包含,否则文件相同
- 删除内存空间后,指针的值保持不变还是更改?对象内容是否将被更改
- 如何在堆栈上为非默认构造对象保留空间
- 获取对象空间到纹理空间的切线