Protection Engine for Cloud Services

 View Only

File is getting corrupted after scan - SymJava.jar (7.0.2.4)

  • 1.  File is getting corrupted after scan - SymJava.jar (7.0.2.4)

    Posted Aug 23, 2013 12:07 AM
      |   view attached

    Hi,

    I am facing an issue with Scanner Socket OutputStream. (SymJava.jar 7.0.2.4)

    After scanning the file(docx, csv, txt), Symantec scan engine is appending ‘0’ at the EOF which in turn causing file corruption.

     

    Scan observations:

     

    S.no

    File Name

    No of bytes before SCAN - input to the send method

    No of bytes after Scan – Returned by Symantec engine

    Difference

    1

    Test.txt

    4 bytes

    11 bytes

    7 bytes

    2

    Test.docx

    12573 bytes

    12580 bytes

    7 bytes

     

     

    I believe these extra 7 bytes are causing problem and appending ‘0’ at the end. It might possible that Symantec API is writing some[7 bytes] 'end of bytes i.e. CR LF' to the SocketOutputStream which is causing the problem.

     

    Observations:

    • When I tried to  scan .txt file     - Scanner output is having ‘0’ at the end.
    • When I tried to scan .docx file   -  File is getting corrupted.

    Code snippet:

    try {

                         do {

                               if (bytesToRead >= buffCapRead) {

                                      buffCapRead = buff.length;

                               } else {

                                      buffCapRead = (int) bytesToRead;

                               }

                               // Refresh data buffer.

                               buff = new byte[buffCapRead];

     

                               bytesRead = fin.read(buff, 0, buffCapRead);

                              // Send the bytes to Symantec Protection Engine

                               streamScanReq.send(buff, 0, buffCapRead);

                                bytesToRead = bytesToRead - bytesRead;

     

                         } while (bytesToRead > 0);

     

                         result = finishScan(streamScanReq);

                 

                  } finally {

                         if (fin != null) {

                               try {

                                      fin.close();

                               } catch (IOException e) {

                                      // TODO Auto-generated catch block

                                      e.printStackTrace();

                               }

                         }

                         if (output != null) {

                               try {

                                      output.close();

                               } catch (IOException e) {

                                      // TODO Auto-generated catch block

                                      e.printStackTrace();

                               }

                         }

    I've cross checked the inputstream and found we are passing correct no of bytes to the scanner but scanner in turn writting 7 extra bytes at the end. this behaviour is consistant for many file extensions.

    Looking forward for you valuable comments and suggestions to get appropriate outputstream out of Scanner engine.

    Thanks,

    Anmol

     

     

     

    Attachment(s)

    docx
    Scan.docx   97 KB 1 version