Open XML Application Security (4) Document validation

Source: Internet
Author: User
Tags file size

When an Office application opens an Office document, it starts with a checksum, primarily verifying the validity and integrity of the document.

When you arbitrarily change the suffix of an EXE document to docx, opening the file will definitely invalidate the file. For an Open XML document, if you want to verify it, there are several aspects:

Q is not a zip compression package

Q Does the necessary part exist

Q is the relationship complete

Q Does the part type match

Q File Size

Q Macros and OLE objects

There are a lot of ways to verify this, and here's the simplest way to use the Openxmlvalidator object in the Open XML SDK. Code Listing 14-24 is a way to verify the validity of a Word document.

Code Listing 14-24 Verifying document validity

 public static void Validateworddocument (string filepath) {try {openxmlvalidator Valida
  
        Tor = new Openxmlvalidator ();
  
        int count = 0; foreach (Validationerrorinfo error in validator.)
  
            Validate (Wordprocessingdocument.open (filepath, True)) {count++;
  
            Console.WriteLine ("Error" + count); Console.WriteLine ("Description:" + error.)
  
            Description); Console.WriteLine ("ErrorType:" + error.)
  
            ErrorType); Console.WriteLine ("Node:" + error.)
  
            Node); Console.WriteLine ("Path:" + error.)
  
            Path.xpath); Console.WriteLine ("Part:" + error.)
  
            Part.uri);
  
        Console.WriteLine ("-------------------------------------------");
  
    } console.readkey (); The catch (Exception ex) {Console.WriteLine (ex).
  
    message); }
  
}

In Listing 14-24, it's easy to verify a document by simply using the Openxmlvalidator Validate method. The method needs to provide a Wordprocessingdocument object as a parameter and return a collection of Validationerrorinfo objects. The Validationerrorinfo object provides us with the basic description, type, node, path, and part of the error that occurred.

--------------Note: This part of the text is adapted from the ". NET Security Secrets"

Author: Hyun-Soul

Source: http://www.cnblogs.com/xuanhun/

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/web/XML/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.