Menu

#32 Data corruption when uploading files in cms

v2.0
closed-fixed
nobody
5
2006-12-12
2005-04-19
No

All files uploaded within cofax (when adding an
articleImage for example) are corrupted if they contain a
specific sequence of bytes.

When a file contains the binary sequence : 0A 0D 0A
(lf cr lf), 0D is dropped at upload.

This is because end of lines caracters are always
removed before writing in the file. They are saved in a
buffer (endOfLineBytes) and added afterward if there is
more data. But the buffer is updated only if data length
is > 0 AFTER removing the end of line.

In this case 0D 0A is removed but the buffer is not
updated and still contains 0A.

0A 0A is written instead of 0A 0D 0A.

Fix : org.cofax.cms.MultipartRequest
in readAndWriteFile(InputStream in, String strFilename)

replace :
if (length > 0) {
// Fix...
if (file != null) {
file.write(blockOfBytes, 0, length);
// Update file size.
fileSize += length;
}

// Now store the line ending, so we can spew it out if
not at the boundary.
if (endOfLineBytes == null || endOfLineBytes.length !=
read - length)
endOfLineBytes = new byte[read - length];

System.arraycopy(blockOfBytes, length,
endOfLineBytes, 0, endOfLineBytes.length);
}

by :

if (length > 0) {
// Fix...
if (file != null) {
file.write(blockOfBytes, 0, length);
// Update file size.
fileSize += length;
}
}

// Now store the line ending, so we can spew it out if not
at the boundary.
if (endOfLineBytes == null || endOfLineBytes.length !=
read - length)
endOfLineBytes = new byte[read - length];

System.arraycopy(blockOfBytes, length,
endOfLineBytes, 0, endOfLineBytes.length);

Discussion

  • Nobody/Anonymous

    Cofax upload bug : try to add this jpg to an article

     
  • F.X. Robin

    F.X. Robin - 2006-12-12

    Logged In: YES
    user_id=1283696
    Originator: NO

    Working. Tested with the JPG file

     
  • F.X. Robin

    F.X. Robin - 2006-12-12
    • status: open --> closed-fixed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.