none
Will C# classes will clean virus after I cropped / shrink an upload image with virus? RRS feed

  • Question

  • Hi everyone,

    I do have a question about the uploaded file with virus.

    I know the common way to deal with this issue is to do a virus scan while uploading.

    But my question is will the C# code will clean the virus after I cropped or shrink an uploaded image with virus?

    Or will it thrown an exception?

    The working scenario is:

    1, user upload an file using my web service. (I am passing the byte array to the server.)

    2,  create  an image code info.

    ImageCodecInfo jpgInfo = ImageCodecInfo.GetImageEncoders().Where(codecInfo => codecInfo.MimeType == "image/jpeg").First();

    3, use Bitmap and Graphics classes to adjust the image to an fix width.

    4, use Image.Save method to save the new image on the server.

    I am not so familiar with how virus work, so,

    Will this process clean the virus for me? Or is there any Exception will thrown if the uploaded image has virus with it?

    Thank you so much for your help.

    Monday, July 28, 2014 11:27 AM

Answers

  • C# and antivirus don't have anything related.  AV works by scanning the file system and resident memory.  If you open (or save perhaps) anything to the file system then your AV should be scanning.  It depends upon how your AV is configured as to whether it'll attempt to clean the file (meaning you'll be able to open it) or quarantine it (which means your app will fail to open it).  In most cases the practical solution is to save a file on the file system somewhere so AV scans it.  Then you can open the file (if cleaned) or fail (if quarantined).  What you do with it after that is irrelevant.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    Monday, July 28, 2014 2:46 PM
    Moderator