Return-Path: X-Original-To: apmail-chemistry-dev-archive@www.apache.org Delivered-To: apmail-chemistry-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 63BC7EF99 for ; Tue, 15 Jan 2013 10:59:57 +0000 (UTC) Received: (qmail 61066 invoked by uid 500); 15 Jan 2013 10:59:57 -0000 Delivered-To: apmail-chemistry-dev-archive@chemistry.apache.org Received: (qmail 60875 invoked by uid 500); 15 Jan 2013 10:59:56 -0000 Mailing-List: contact dev-help@chemistry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@chemistry.apache.org Delivered-To: mailing list dev@chemistry.apache.org Received: (qmail 60851 invoked by uid 99); 15 Jan 2013 10:59:56 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Jan 2013 10:59:56 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [64.131.68.102] (HELO vps.elilink.com) (64.131.68.102) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Jan 2013 10:59:46 +0000 Received: from [212.98.167.242] (port=32516 helo=dandreev) by vps.elilink.com with esmtpa (Exim 4.77) (envelope-from ) id 1Tv4Em-0000Qv-5N; Tue, 15 Jan 2013 05:59:24 -0500 From: "Denis Andreev" To: Cc: "Alfresco Team" Subject: DotCMIS issue in DotCMIS.Binding.AtomPub.AtomEntryWriter.WriteContent() Date: Tue, 15 Jan 2013 13:59:19 +0300 Message-ID: <001a01cdf30f$5f04edf0$1d0ec9d0$@com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_001B_01CDF328.845225F0" X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ac3zD13yUY8o8hx8RXix3jCfeTJfJQ== Content-Language: en-us X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vps.elilink.com X-AntiAbuse: Original Domain - chemistry.apache.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - elilink.com X-Virus-Checked: Checked by ClamAV on apache.org ------=_NextPart_000_001B_01CDF328.845225F0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi Everyone There is an issue in the method DotCMIS.Binding.AtomPub.AtomEntryWriter.WriteContent() private void WriteContent(XmlWriter writer) { using (var br = new BinaryReader(stream)) { var buffer = new byte[BufferSize]; int readBytes = 0; do { readBytes = br.Read(buffer, 0, BufferSize); writer.WriteBase64(buffer, 0, readBytes); } while (BufferSize <= readBytes); } } The problem is that the method "Stream.Read() or BinaryReader.Read()" may read less amount of bytes than the provided buffer size when the end of the stream has not been reached yet. For example. The file "File1.txt" of size 30K is requested by HttpWebRequest to download from a server and transfer it to Alfresco. HttpWebRequest returns System.Net.ConnectStream. The buffer size to read from stream is 65K. In the code above the first read operation returns 4K from the stream and the condition "while (BufferSize <= readBytes)" finishes the read cycle. I've fixed the problem with the code below. The read cycle should continue working unit Read returns the value != 0: private void WriteContent(XmlWriter writer) { using (var br = new BinaryReader(stream)) { var buffer = new byte[BufferSize]; int readBytes = 0; while ((readBytes = br.Read(buffer, 0, BufferSize)) != 0) { writer.WriteBase64(buffer, 0, readBytes); } /* do { readBytes = br.Read(buffer, 0, BufferSize); writer.WriteBase64(buffer, 0, readBytes); } while (BufferSize <= readBytes); */ } } Would you please consider this code and update DotCMIS library. Best regards, Denis Andreev ------=_NextPart_000_001B_01CDF328.845225F0--