From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 0BC066EC56; Sun, 14 Mar 2021 19:23:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0BC066EC56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1615739014; bh=KrnKr0cZ98p1cLmD2r0tVxoHxA2OGCx4PUdLpSNFm4M=; h=To:References:Date:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=UZBntVvRUbJl4mdQfg4gL/4GbsxbkdEVKxMhaMdkVRV2Fcijv6gswYeui7EQofxLW d5Sh0TMDKDuujRZv8sdfksFuj/zCJfQZwyxzUm3V9i+MFteJaewelIaNq/VYsfWTYN UcCW3YaSZ5Q1EJRAf2qV0X6qOli6QieinyFfouw4= Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 5E8896EC56 for ; Sun, 14 Mar 2021 19:23:33 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5E8896EC56 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lLTWe-0000XP-6b; Sun, 14 Mar 2021 19:23:32 +0300 To: Alexander Turenko , Sergey Nikiforov References: <7214add2c7f2a86265a5e08f2184029a19fc184d.1615283860.git.void@tarantool.org> <20210312142707.2apjwermnixygb4t@tkn_work_nb> Message-ID: <690f6767-d325-fa99-7410-49b7fac2ac08@tarantool.org> Date: Sun, 14 Mar 2021 17:23:31 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <20210312142707.2apjwermnixygb4t@tkn_work_nb> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9D3134714A9BDB69B63430D3F1B4C5913A95494451A5CA18200894C459B0CD1B9717D3E1127201E04CB4765004BFA5E0842B63D32119EB8B87A2D8C9EC3405942 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7DB84ED444C624799EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006374ECA27954A00B6C3EA1F7E6F0F101C67CDEEF6D7F21E0D1D174C73DBBBFC76646EEDF601740AEF524775D9634F094087120D7E4495FB21E8389733CBF5DBD5E913377AFFFEAFD269A417C69337E82CC2CC7F00164DA146DAFE8445B8C89999729449624AB7ADAF37F6B57BC7E64490611E7FA7ABCAF51C92176DF2183F8FC7C0D9442B0B5983000E8941B15DA834481F9449624AB7ADAF3735872C767BF85DA29E625A9149C048EE0A3850AC1BE2E7358CCB3ED2A1DE23044AD6D5ED66289B524E70A05D1297E1BB35872C767BF85DA227C277FBC8AE2E8BED2B17DC88CE1EFE75ECD9A6C639B01B4E70A05D1297E1BBC6867C52282FAC85D9B7C4F32B44FF57E8FBB06288C1946000306258E7E6ABB4E4A6367B16DE6309 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2BBE337FB72E923155C0AF1600DCBC20B2E9DF445054C0E62D0E1A3B008041CDB X-C1DE0DAB: 0D63561A33F958A5DFF6D42E6FAEB16CB9D1167706A82E0BE720A64E657C9A4BD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75F04B387B5D7535DE410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34A9A0A0BF1A2CAC628C812C9D94A094215EA855BB3889AF31720424AAC1CDA7C59D7839FF0D947C311D7E09C32AA3244CE850444880138917AE59C410469139135A1673A01BA68E40927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj4I/mOTH/3lEfA9ZQRtFlog== X-Mailru-Sender: 689FA8AB762F73936BC43F508A0638228F8ADBC61B40FB65ABCECF7A9563B9F43841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v8] base64: fix decoder output buffer overrun (reads) X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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);