tstream 可以防止缓冲区溢出吗?

发布于 2024-12-04 21:46:53 字数 191 浏览 0 评论 0原文

TStream 是一个抽象类。

然而,关于它的实现,它们能证明缓冲区溢出吗?

如果我从互联网上的非我来源获取流,我如何验证它没有损坏并导致缓冲区溢出?

假设流是一个 xml 文件。

编辑: 所有答案都表明您需要检查缓冲区溢出。 您能否演示如何检查输入文件上的缓冲区溢出,其中我们知道流的定义可能是无限的?

TStream is an abstract class.

However about its implementations, are they buffer overflow proof?

If I'm fetching a stream from the internet, from a source that is not me, how do I verify that it is not corrupted and cause buffer overflow?

Lets say that the stream is an xml file.

edit:
all the answers indicate you need to check for buffer overflow.
could you demonstrate how to check a buffer overflow on an input file, where we know that a stream could be infinite by its definition?

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

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

发布评论

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

评论(4

烧了回忆取暖 2024-12-11 21:46:53

据我所知,TStream 及其各种 RTL 后代不存在任何导致缓冲区溢出的错误。

然而,使用 Delphi 流的代码很容易超出缓冲区。

TStream and its various RTL descendents do not have any bugs that result in buffer overruns, to the best of my knowledge.

However, your code using Delphi streams could easily overrun a buffer.

命硬 2024-12-11 21:46:53

TStream 读入调用者提供的任何缓冲区。调用者有责任确保提供的缓冲区及其大小有效。

TStream reads into whatever buffer the caller supplies. It is the caller's responsibility to make sure the supplied buffer and its size are valid.

老娘不死你永远是小三 2024-12-11 21:46:53

通常,您应该在填充之前根据所显示流的 Size 属性来设置自己的缓冲区的大小。 Size 属性未提供实际大小的唯一原因是 Seek 方法的实现错误。除非该方法根据奇怪的边界假设确定流的大小,否则单个测试应该排除任何问题。

无论如何,无论流是否包含损坏的数据,只要您下载的数据不超过自己缓冲区的大小,就永远不会遇到缓冲区溢出问题。

您还可以请求所呈现的流的类型并验证它是否是标准的 Delphi 流。如果是这样,那么您不必担心。

Normally, you should depend on the Size property of the presented stream to set the size of your own buffer before filling it. The only reason for that Size property not delivering the real size would be a wrong implementation of either Seek methods. Unless that method determines the size of the stream on weird boundary assumptions, a single test should rule out any problems.

In any case, whether the stream contains corrupted data or not, it should néver run into a buffer overflow on your side if you just not download more than the size of your own buffer.

You could also request the type of the presented stream and verify if it is a standard Delphi stream. If so, then you need not be worried.

刘备忘录 2024-12-11 21:46:53

不,TStream 后代不是“防溢出”的。但如果您遵循 Remy 和 NGLN 的建议,您将使用 Delphi 流编写尽可能安全的代码。

如果您担心某些恶意内容,请在 try/ except 和/或 try/finally 阻止中处理它并清除任何潜在的损害。

正确使用“try”是 Delphi 编程安全的关键——没有灵丹妙药。这就是当您使用编译语言时所付出的代价,而不是让您“接近金属”。

No, TStream descendants are not 'overflow proof'. But if you follow the advice of Remy and NGLN, you will write code that is as safe as possible with Delphi streams.

If you are afraid of something malicious, handle it within a try/except and/or try/finally block and clean up any potential damage.

Correct usage of 'try' is the key to SAFE Delphi programming - there are no silver bullets. That is the price you pay when you use a compiled language than allows you to get 'close to the metal'.

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