TinyTinni / ValveFileVDF

C++ Parser and Writer for Valve Data Format (e.g. .vdf files used in steam)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to parse files with abnormal encoding causing program crashes

MrHulu opened this issue · comments

Dear Contributors

Environment

  • branches: [master]
  • Build System: [CMake]
  • Operating System: [Windows]

Problem Description

As the title states,When I parse an encoding exception file, an exception 0xC0000005 is thrown.

Steps to reproduce

  1. Add vdf_parser.hpp file in my test project
  2. Writing my test code
int main(int argc, char *argv[])
{
    std::list<std::string> list{
        "C:/Users/Administrator/Desktop/steamapps/appmanifest_a.acf",
        "C:/Users/Administrator/Desktop/steamapps/appmanifest_b.acf",
        "C:/Users/Administrator/Desktop/steamapps/appmanifest_b.acf",
    };
    for(auto path : list) {
        try{
            std::ifstream file(path);
            auto root = tyti::vdf::read(file);
            std::cout << path  << std::endl;
            for(auto [l, r] : root.attribs) {
                std::cout << l << " : " << r << std::endl;
            }
            std::cout << "--------------" <<std::endl;
        }catch(std::exception& e) {
            std::cout << path << e.what() << std::endl;
        }
    }
    return 0;
}
  1. The exception is then thrown

Debug Logs

Exception thrown at 0x00C8D2E6 in TestSketch.exe: 0xC0000005: Access violation reading location 0x0000003C.

appmanifest_a.zip
Here I provide an exception file.

Hi,
in what encoding is the file? Neither ANSI with randomly codepgaes, nor utf8/16 show me any results.

Is this a binary file? Binary files are not supported by the parser as I cannot find any real specification to it. So it must be a text file. See https://developer.valvesoftware.com/wiki/KeyValues#About_KeyValues_Text_File_Format

if you know the encoding, try to change your locale or try to use wchar_t.

if you know the encoding, try to change your locale or try to use wchar_t.

Hi, TinyTinni, In fact, I can't be sure of the encoding of this file, which is generated by the file Steam.


My idea is, do we need to make some security treatment to avoid the file encoding non-conformity to crash the program when we can't be sure if the encoding of the file is canonical or not?

My idea is, do we need to make some security treatment to avoid the file encoding non-conformity to crash the program when we can't be sure if the encoding of the file is canonical or not?

I totally agree, it should be fixed. I just wanted to clarify, that the file cannot be parsed by this parser, even when the crash is fixed.