From: Petteri Hintsanen <petterih@iki.fi>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
Subject: Re: Bindat can exhaust memory when unpacking to vector
Date: Tue, 19 Mar 2024 22:09:44 +0200 [thread overview]
Message-ID: <87a5mukmpj.fsf@iki.fi> (raw)
In-Reply-To: <jwvjzm9ix5f.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Sun, 10 Mar 2024 17:58:14 -0400")
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> (defconst foo-bindat-spec
>> (bindat-type
>> (length uint 32)
>> (_ unit (when (> length 1234) (error "malicious input")))
>> (data vec length)))
>>
>> Which is somewhat messy, but it works.
>
> You should also be able to do
>
> (defconst foo-bindat-spec
> (bindat-type
> (length uint 32)
> (data vec (if (< length 1234) length (error "malicious input")))))
>
> as well. But it's still not very elegant.
Ah sure, right. This is nice I think.
> (defconst foo-bindat-spec
> (bindat-type
> (length uint 32)
> (data vec (bounded 1 length 1234))))
>
> so we signal an error if the length is less than 1 or larger than 1234.
Sure. But I'm not sure which kind of helpers would be the most
beneficial for general use. Like said, I don't have that many examples,
and for my few validation cases I have found the "unit type" to be good
enough.
>> I also played around with the idea of patching bindat.el itself to do
>> trivial checking against the input data size, like this:
>> [...]
> Actually, this is a nice solution, I think.
> It seems hypothetical enough that I think we should go with your patch.
Feel free to apply it in whatever form you want, if you think it is
appropriate.
>> Checking should be optional and somehow programmable, perhaps
>> a separate "checked vec" type? (I don't have any good, concrete
>> ideas, sorry.)
>
> I don't see the benefit of not-checking, to be honest.
I probably thought about efficiency here. If bindat-unpack is hammered
many many many times and the checking could be _safely_ ignored, then,
perhaps, there might be a noticeable difference in performance. Or
maybe not.
Thanks,
Petteri
next prev parent reply other threads:[~2024-03-19 20:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-22 19:36 Bindat can exhaust memory when unpacking to vector Petteri Hintsanen
2023-10-23 11:25 ` Eli Zaretskii
2023-10-23 19:36 ` Petteri Hintsanen
2023-10-24 4:34 ` tomas
2023-11-12 19:11 ` Petteri Hintsanen
2023-11-04 7:48 ` Eli Zaretskii
2023-11-04 8:21 ` Stefan Monnier
2024-03-10 21:58 ` Stefan Monnier
2024-03-19 20:09 ` Petteri Hintsanen [this message]
2024-03-19 21:08 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a5mukmpj.fsf@iki.fi \
--to=petterih@iki.fi \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).