From patchwork Thu Jul 21 09:56:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaac Lozano <109lozanoi@gmail.com> X-Patchwork-Id: 9241345 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 968F6602F0 for ; Thu, 21 Jul 2016 09:57:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8672A212BE for ; Thu, 21 Jul 2016 09:57:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B3E8277D9; Thu, 21 Jul 2016 09:57:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,FROM_STARTS_WITH_NUMS,RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1B46A212BE for ; Thu, 21 Jul 2016 09:57:37 +0000 (UTC) Received: from localhost ([::1]:39488 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQAjY-0005eg-CT for patchwork-qemu-devel@patchwork.kernel.org; Thu, 21 Jul 2016 05:57:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57766) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <109lozanoi@gmail.com>) id 1bQAj5-0005cT-91 for qemu-devel@nongnu.org; Thu, 21 Jul 2016 05:57:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <109lozanoi@gmail.com>) id 1bQAj1-0003dz-P7 for qemu-devel@nongnu.org; Thu, 21 Jul 2016 05:57:07 -0400 Received: from mail-pa0-x242.google.com ([2607:f8b0:400e:c03::242]:33314) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <109lozanoi@gmail.com>) id 1bQAj1-0003dr-IN for qemu-devel@nongnu.org; Thu, 21 Jul 2016 05:57:03 -0400 Received: by mail-pa0-x242.google.com with SMTP id q2so4985381pap.0 for ; Thu, 21 Jul 2016 02:57:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=6VNkRN936BAT4AmEsjai3yDSjtzdkAithUW9uNgIjb8=; b=oDRzRIeQGWrmy2ux4Lzu/PesL2TLoiOAD3S5ELfsLrFAaYNK61i9tdl9dFC7JyNkAB l25ulegUAyCiSK/FkWZjwWfMUbKglIPLGa8AHqjiRstU9JfuvwDF1093UAoXai0183dJ r/f4gHNxYIh/47l62BmqL7XZc1PilY5WXG3NYrag9AfOGjRe6SJdUVirvZx3YEblcG6I SbzjSd+s7krxrNTUs95kytXHkL55yAUvzTwh399vNouO++vqR2ufaIcy5ta7n5JJ+xvW K4isRW+wVQm6Ak+KJifrMnXt0XwrPEsHj+EdAd+bNS6EvSoP2IlZSalXEPn4nZfQjc/z GIDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=6VNkRN936BAT4AmEsjai3yDSjtzdkAithUW9uNgIjb8=; b=Qnrc6P45uBJlADV47UHwiHIHGKO1iXbouM57oBRgm4jsq8JTBQn2Hp8i2/WgBuY082 iPON2G7ZTpq04KJk0LxaDA78SE0PUmuvRlwMUT0qYBJUDaRDF7wYxNVlisZAGj7uhD8q o2/cscnJfuQ5kwItkbth1vujqG+TKp5zRPFQjMNh3XVnWQ43GsnhnVfgv5tnzVkhzYoc rvzuzhVmuC0lBFv/RsNixCBfxBouG3J56waro/x7xyPS9wtgq0VsMVUix1dL62RK8N4B 1yDGO2BFD2ohnNt9TdSWU05FyOyD+K/qPLIruN8ckFw4SGFm/mKLtj0kowcetZ+gHTap 8U1g== X-Gm-Message-State: ALyK8tK7FC9NJSfzBMRWNQW2D+oljltuKl7B0HGfutZD34QcuilmB+PXbwj0Xd/8iod6XA== X-Received: by 10.66.145.1 with SMTP id sq1mr81646088pab.107.1469095022722; Thu, 21 Jul 2016 02:57:02 -0700 (PDT) Received: from localhost.localdomain (23-114-218-5.lightspeed.frokca.sbcglobal.net. [23.114.218.5]) by smtp.gmail.com with ESMTPSA id d3sm10831355pfk.37.2016.07.21.02.57.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jul 2016 02:57:01 -0700 (PDT) From: Isaac Lozano <109lozanoi@gmail.com> To: qemu-devel@nongnu.org Date: Thu, 21 Jul 2016 02:56:33 -0700 Message-Id: <13b6f9d93dc97dc36cc89867348c00f13d49526d.1468876280.git.109lozanoi@gmail.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c03::242 Subject: [Qemu-devel] [PATCH v2 1/2] usb-mtp: fix sending files larger than 4gb X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Isaac Lozano <109lozanoi@gmail.com>, bsd@redhat.com, kraxel@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP MTP requires that if a file is larger than 4gb or if sending data larger than 4gb, that the length field be set to 0xFFFFFFFF. Also widened a couple variables to prevent overflow errors. Signed-off-by: Isaac Lozano <109lozanoi@gmail.com> Reviewed-by: Bandan Das --- hw/usb/dev-mtp.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index 1be85ae..6f6a270 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -115,8 +115,8 @@ struct MTPControl { struct MTPData { uint16_t code; uint32_t trans; - uint32_t offset; - uint32_t length; + uint64_t offset; + uint64_t length; uint32_t alloc; uint8_t *data; bool first; @@ -883,7 +883,13 @@ static MTPData *usb_mtp_get_object_info(MTPState *s, MTPControl *c, usb_mtp_add_u32(d, QEMU_STORAGE_ID); usb_mtp_add_u16(d, o->format); usb_mtp_add_u16(d, 0); - usb_mtp_add_u32(d, o->stat.st_size); + + if (o->stat.st_size > 0xFFFFFFFF) { + usb_mtp_add_u32(d, 0xFFFFFFFF); + } + else { + usb_mtp_add_u32(d, o->stat.st_size); + } usb_mtp_add_u16(d, 0); usb_mtp_add_u32(d, 0); @@ -1193,10 +1199,15 @@ static void usb_mtp_handle_data(USBDevice *dev, USBPacket *p) } if (s->data_in != NULL) { MTPData *d = s->data_in; - int dlen = d->length - d->offset; + uint64_t dlen = d->length - d->offset; if (d->first) { trace_usb_mtp_data_in(s->dev.addr, d->trans, d->length); - container.length = cpu_to_le32(d->length + sizeof(container)); + if (d->length + sizeof(container) > 0xFFFFFFFF) { + container.length = cpu_to_le32(0xFFFFFFFF); + } + else { + container.length = cpu_to_le32(d->length + sizeof(container)); + } container.type = cpu_to_le16(TYPE_DATA); container.code = cpu_to_le16(d->code); container.trans = cpu_to_le32(d->trans);