From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Alexander Turenko <alexander.turenko@tarantool.org>, Sergey Nikiforov <void@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH v8] base64: fix decoder output buffer overrun (reads) Date: Sun, 14 Mar 2021 17:23:31 +0100 [thread overview] Message-ID: <690f6767-d325-fa99-7410-49b7fac2ac08@tarantool.org> (raw) In-Reply-To: <20210312142707.2apjwermnixygb4t@tkn_work_nb> Hi! Thanks for the patch! Looks good, but you check out_pos in the inner loops even though it does not change inside of them. Consider the diff below. But I didn't bench it. Probably the compiler moved the check out of the loops anyway in your version. I didn't check that either. The tests pass though. ==================== @@ -235,30 +235,41 @@ base64_decode(const char *in_base64, int in_len, while (1) { + if (out_pos >= out_end) + return out_pos - out_bin; do { - if (in_pos == in_end || out_pos >= out_end) + if (in_pos == in_end) return out_pos - out_bin; fragment = base64_decode_value(*in_pos++); } while (fragment < 0); *out_pos = (fragment & 0x03f) << 2; + + if (out_pos >= out_end) + return out_pos - out_bin; do { - if (in_pos == in_end || out_pos >= out_end) + if (in_pos == in_end) return out_pos - out_bin; fragment = base64_decode_value(*in_pos++); } while (fragment < 0); *out_pos++ |= (fragment & 0x030) >> 4; + if (out_pos < out_end) *out_pos = (fragment & 0x00f) << 4; + else + return out_pos - out_bin; do { - if (in_pos == in_end || out_pos >= out_end) + if (in_pos == in_end) return out_pos - out_bin; fragment = base64_decode_value(*in_pos++); } while (fragment < 0); *out_pos++ |= (fragment & 0x03c) >> 2; + if (out_pos < out_end) *out_pos = (fragment & 0x003) << 6; + else + return out_pos - out_bin; do { - if (in_pos == in_end || out_pos >= out_end) + if (in_pos == in_end) return out_pos - out_bin; fragment = base64_decode_value(*in_pos++); } while (fragment < 0);
next prev parent reply other threads:[~2021-03-14 16:23 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-03-09 9:59 Sergey Nikiforov via Tarantool-patches 2021-03-12 14:27 ` Alexander Turenko via Tarantool-patches 2021-03-14 16:23 ` Vladislav Shpilevoy via Tarantool-patches [this message] 2021-03-19 15:47 ` Kirill Yukhin via Tarantool-patches
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 * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=690f6767-d325-fa99-7410-49b7fac2ac08@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=alexander.turenko@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --cc=void@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v8] base64: fix decoder output buffer overrun (reads)' \ /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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox