怎么可能在一个平台上发生缓冲区溢出,而在另一个平台上却不会发生缓冲区溢出?

发布于 2024-10-18 12:08:22 字数 256 浏览 2 评论 0原文

由于情况含糊,我很犹豫是否要问这个问题,但我想了解这是怎么可能的。我有一个使用 Visual Studio 2008 开发的 C++ 应用程序。当我在 Windows 7 64 位(或 Vista 32 位)上编译该应用程序时,该应用程序运行良好。当我在 32 位 Windows XP SP3 上编译应用程序时,我收到缓冲区溢出警告,并且进程终止。它使用相同版本的 Visual Studio 2008 C++ 编译器。为什么我在 XP 上收到缓冲区溢出,但在其他 Windows 平台上却没有?

I'm hesitant to ask this question because of the vagueness of the situation, but I'd like to understand how this is possible. I have a C++ application developed using Visual Studio 2008. When I compile the application on Windows 7 64-bit (or Vista 32-bit), the application runs fine. When I compile the application on 32-bit Windows XP SP3, I receive a buffer overrun warning and the process terminates. This is using the same verison of the Visual Studio 2008 C++ compiler. How is it that I receive a buffer overrun on XP, but not on other Windows platforms?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

双手揣兜 2024-10-25 12:08:22

编写代码,这样就不会出现缓冲区溢出,并且在任何平台上都不会出现此问题。也就是说,请确保检查正在访问的缓冲区的边界,以确保您不会尝试在正确的边界之外进行读/写。

Write code so you don't have buffer overruns and you won't have this problem on any platform. Namely, make sure you check the bounds for the buffer you are accessing to make sure you aren't trying to read/write outside of the proper bounds.

酒中人 2024-10-25 12:08:22

幸运的是,宇宙的根本不确定性,或者(比以前更有可能)在 XP 和 7 之间 msvcrt.dll 中发生了更改的实现细节。

底线是您的应用程序中存在错误,您应该修复它。

Luck, the fundamental undeterminedness of the Universe, or (more likely than the previous) an implementation detail that changed in msvcrt.dll between XP and 7.

Bottom line is you have a bug in your application, and you should fix it.

默嘫て 2024-10-25 12:08:22

在这两种情况下,您可能都会遇到缓冲区溢出,在第一种情况下,它未被检测到并且(显然)不会造成任何损害。在第二个中它被检测到。 (如果它位于动态分配的内存上,您必须知道分配器通常会分配比要求的更多的内存,因此一个合理的解释是,在第一种情况下,溢出会保留在该区域中,而在第二种情况下则不会)。

You probably have a buffer overrun in both case, in the first it isn't detected and doesn't (apparently) do any harm. In the second it is detected. (If it is on a dynamically allocated memory, you have to know that allocators often allocate more than what asked, thus a plausible explanation is that in the first case the overrun stay in that zone, in the second it doesn't).

活泼老夫 2024-10-25 12:08:22

数据类型的大小可能会因一个编译器而异(感谢@AndreyT)。使用诸如 sizeof(4) 之类的硬编码数字来表示代码中数据类型的大小,可能会在您的应用程序中弹出错误。您应该使用 sizeof(int) 来代替或使用您感兴趣的任何类型。

Sizes of data types might change from one compiler to another (thanks @AndreyT). Using hardcoded numbers like sizeof(4) to represent the size of a data type on your code, might pop up a bug on your application. You should use sizeof(int) instead or whatever type you are interested in.

梦忆晨望 2024-10-25 12:08:22

Windows-7 有一个称为容错堆的功能,正如它所说,它可以容忍一些错误的缓冲区访问。 Windows XP没有这个功能(Vista,我不知道)。在channel9.msdn.com 或sysinternal.com(忘记具体位置)上有一个由Mark Russinovich 制作的关于它的视频。

Windows-7 has a feature called fault-tolerant-heap which ,as it says, is tolerant about some faulty buffer accesses. Windows XP doesn't have this feature (Vista ,I don't know). There is a video about it on channel9.msdn.com or sysinternal.com (forgot exactly where) by Mark Russinovich.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文