{"action":"created","comment":{"url":"https://api.github.com/repos/alliedmodders/sourcemod/pulls/comments/25422681","id":25422681,"diff_hunk":"@@ -0,0 +1,617 @@\n+// vim: set sts=2 ts=8 sw=2 tw=99 et:\r\n+// \r\n+// Copyright (C) 2004-2015 AlliedModers LLC\r\n+//\r\n+// This file is part of SourcePawn. SourcePawn is licensed under the GNU\r\n+// General Public License, version 3.0 (GPL). If a copy of the GPL was not\r\n+// provided with this file, you can obtain it here:\r\n+//   http://www.gnu.org/licenses/gpl.html\r\n+//\r\n+#include \"smx-v1-image.h\"\r\n+#include \"zlib/zlib.h\"\r\n+\r\n+using namespace ke;\r\n+using namespace sp;\r\n+\r\n+SmxV1Image::SmxV1Image(FILE *fp)\r\n+ : FileReader(fp),\r\n+   hdr_(nullptr),\r\n+   header_strings_(nullptr),\r\n+   names_section_(nullptr),\r\n+   names_(nullptr),\r\n+   debug_names_section_(nullptr),\r\n+   debug_names_(nullptr),\r\n+   debug_syms_(nullptr),\r\n+   debug_syms_unpacked_(nullptr)\r\n+{\r\n+}\r\n+\r\n+// Validating SMX v1 scripts is fairly expensive. We reserve real validation\r\n+// for v2.\r\n+bool\r\n+SmxV1Image::validate()\r\n+{\r\n+  if (length_ < sizeof(sp_file_hdr_t))\r\n+    return error(\"bad header\");\r\n+\r\n+  hdr_ = (sp_file_hdr_t *)buffer();\r\n+  if (hdr_->magic != SmxConsts::FILE_MAGIC)\r\n+    return error(\"bad header\");\r\n+\r\n+  switch (hdr_->version) {\r\n+    case SmxConsts::SP1_VERSION_1_0:\r\n+    case SmxConsts::SP1_VERSION_1_1:\r\n+    case SmxConsts::SP1_VERSION_1_7:\r\n+      break;\r\n+    default:\r\n+      return error(\"unsupported version\");\r\n+  }\r\n+\r\n+  switch (hdr_->compression) {\r\n+    case SmxConsts::FILE_COMPRESSION_GZ:\r\n+    {\r\n+      // The start of the compression cannot be larger than the file.\r\n+      if (hdr_->dataoffs > length_)\r\n+        return error(\"illegal compressed region\");\r\n+\r\n+      // The compressed region must start after the header.\r\n+      if (hdr_->dataoffs < sizeof(sp_file_hdr_t))\r\n+        return error(\"illegal compressed region\");\r\n+\r\n+      // The full size of the image must be at least as large as the start\r\n+      // of the compressed region.\r\n+      if (hdr_->imagesize < hdr_->dataoffs)\r\n+        return error(\"illegal image size\");\r\n+\r\n+      // Allocate the uncompressed image buffer.\r\n+      uint32_t compressedSize = hdr_->disksize - hdr_->dataoffs;\r\n+      AutoArray<uint8_t> uncompressed(new uint8_t[hdr_->imagesize]);\r\n+      if (!uncompressed)\r\n+        return error(\"out of memory\");\r\n+\r\n+      // Decompress.\r\n+      const uint8_t *src = buffer() + hdr_->dataoffs;\r\n+      uint8_t *dest = (uint8_t *)uncompressed + hdr_->dataoffs;\r\n+      uLongf destlen = hdr_->imagesize - hdr_->dataoffs;\r\n+      int rv = uncompress(\r\n+        (Bytef *)dest,\r\n+        &destlen,\r\n+        src,\r\n+        compressedSize);\r\n+      if (rv != Z_OK)\r\n+        return error(\"could not decode compressed region\");\r\n+\r\n+      // Copy the initial uncompressed region back in.\r\n+      memcpy((uint8_t *)uncompressed, buffer(), hdr_->dataoffs);\r\n+\r\n+      // Replace the original buffer.\r\n+      length_ = hdr_->imagesize;\r\n+      buffer_ = uncompressed.take();\r\n+      hdr_ = (sp_file_hdr_t *)buffer();\r\n+      break;\r\n+    }\r\n+\r\n+    case SmxConsts::FILE_COMPRESSION_NONE:\r\n+      break;\r\n+\r\n+    default:\r\n+      return error(\"unknown compression type\");\r\n+  }\r\n+\r\n+  // Validate the string table.\r\n+  if (hdr_->stringtab >= length_)\r\n+    return error(\"invalid string table\");\r\n+  header_strings_ = reinterpret_cast<const char *>(buffer() + hdr_->stringtab);\r\n+\r\n+  // Validate sections header.\r\n+  if ((sizeof(sp_file_hdr_t) + hdr_->sections * sizeof(sp_file_section_t)) > length_)\r\n+    return error(\"invalid section table\");\r\n+\r\n+  size_t last_header_string = 0;\r\n+  const sp_file_section_t *sections =\r\n+    reinterpret_cast<const sp_file_section_t *>(buffer() + sizeof(sp_file_hdr_t));\r\n+  for (size_t i = 0; i < hdr_->sections; i++) {\r\n+    if (sections[i].nameoffs >= (hdr_->dataoffs - hdr_->stringtab))\r\n+      return error(\"invalid section name\");\r\n+\r\n+    if (sections[i].nameoffs > last_header_string)\r\n+      last_header_string = sections[i].nameoffs;\r\n+\r\n+    sections_.append(Section());\r\n+    sections_.back().dataoffs = sections[i].dataoffs;\r\n+    sections_.back().size = sections[i].size;\r\n+    sections_.back().name = header_strings_ + sections[i].nameoffs;\r\n+  }\r\n+\r\n+  // Validate sanity of section header strings.\r\n+  bool found_terminator = false;\r\n+  for (const uint8_t *iter = buffer() + last_header_string;\r\n+       iter < buffer() + hdr_->dataoffs;\r\n+       iter++)\r\n+  {\r\n+    if (*iter == '\\0') {\r\n+      found_terminator = true;\r\n+      break;\r\n+    }\r\n+  }\r\n+  if (!found_terminator)\r\n+    return error(\"malformated section name\");\r","path":"sourcepawn/jit/smx-v1-image.cpp","position":138,"original_position":138,"commit_id":"7d38429632c1c0c7fa1e919dbef83cbc7e47260a","original_commit_id":"7d38429632c1c0c7fa1e919dbef83cbc7e47260a","user":{"login":"Fyren","id":3320115,"avatar_url":"https://avatars.githubusercontent.com/u/3320115?v=3","gravatar_id":"","url":"https://api.github.com/users/Fyren","html_url":"https://github.com/Fyren","followers_url":"https://api.github.com/users/Fyren/followers","following_url":"https://api.github.com/users/Fyren/following{/other_user}","gists_url":"https://api.github.com/users/Fyren/gists{/gist_id}","starred_url":"https://api.github.com/users/Fyren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fyren/subscriptions","organizations_url":"https://api.github.com/users/Fyren/orgs","repos_url":"https://api.github.com/users/Fyren/repos","events_url":"https://api.github.com/users/Fyren/events{/privacy}","received_events_url":"https://api.github.com/users/Fyren/received_events","type":"User","site_admin":false},"body":"MALFORMED\r\nMISFORMATTED","created_at":"2015-02-26T12:16:34Z","updated_at":"2015-02-26T12:16:34Z","html_url":"https://github.com/alliedmodders/sourcemod/pull/284#discussion_r25422681","pull_request_url":"https://api.github.com/repos/alliedmodders/sourcemod/pulls/284","_links":{"self":{"href":"https://api.github.com/repos/alliedmodders/sourcemod/pulls/comments/25422681"},"html":{"href":"https://github.com/alliedmodders/sourcemod/pull/284#discussion_r25422681"},"pull_request":{"href":"https://api.github.com/repos/alliedmodders/sourcemod/pulls/284"}}},"pull_request":{"url":"https://api.github.com/repos/alliedmodders/sourcemod/pulls/284","id":30052739,"html_url":"https://github.com/alliedmodders/sourcemod/pull/284","diff_url":"https://github.com/alliedmodders/sourcemod/pull/284.diff","patch_url":"https://github.com/alliedmodders/sourcemod/pull/284.patch","issue_url":"https://api.github.com/repos/alliedmodders/sourcemod/issues/284","number":284,"state":"open","locked":false,"title":"Rewrite the .smx parser.","user":{"login":"dvander","id":865306,"avatar_url":"https://avatars.githubusercontent.com/u/865306?v=3","gravatar_id":"","url":"https://api.github.com/users/dvander","html_url":"https://github.com/dvander","followers_url":"https://api.github.com/users/dvander/followers","following_url":"https://api.github.com/users/dvander/following{/other_user}","gists_url":"https://api.github.com/users/dvander/gists{/gist_id}","starred_url":"https://api.github.com/users/dvander/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dvander/subscriptions","organizations_url":"https://api.github.com/users/dvander/orgs","repos_url":"https://api.github.com/users/dvander/repos","events_url":"https://api.github.com/users/dvander/events{/privacy}","received_events_url":"https://api.github.com/users/dvander/received_events","type":"User","site_admin":false},"body":"This removes one the last remnants of the SourceMod 1.0 VM implementation.\r\n\r\nThe new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.\r\n\r\nInternally, the sp_plugin_t structre has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.\r\n\r\nPluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.\r\n\r\nFinally, some aspects of the loading process have been cleaned up. The decompression and image handoff logic should now be easier to understand.","created_at":"2015-02-26T05:58:55Z","updated_at":"2015-02-26T12:16:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1a5e6c6e3a6f3f05dd40049331372d50c63aa8ed","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/alliedmodders/sourcemod/pulls/284/commits","review_comments_url":"https://api.github.com/repos/alliedmodders/sourcemod/pulls/284/comments","review_comment_url":"https://api.github.com/repos/alliedmodders/sourcemod/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alliedmodders/sourcemod/issues/284/comments","statuses_url":"https://api.github.com/repos/alliedmodders/sourcemod/statuses/7d38429632c1c0c7fa1e919dbef83cbc7e47260a","head":{"label":"alliedmodders:new-loader","ref":"new-loader","sha":"7d38429632c1c0c7fa1e919dbef83cbc7e47260a","user":{"login":"alliedmodders","id":6601917,"avatar_url":"https://avatars.githubusercontent.com/u/6601917?v=3","gravatar_id":"","url":"https://api.github.com/users/alliedmodders","html_url":"https://github.com/alliedmodders","followers_url":"https://api.github.com/users/alliedmodders/followers","following_url":"https://api.github.com/users/alliedmodders/following{/other_user}","gists_url":"https://api.github.com/users/alliedmodders/gists{/gist_id}","starred_url":"https://api.github.com/users/alliedmodders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alliedmodders/subscriptions","organizations_url":"https://api.github.com/users/alliedmodders/orgs","repos_url":"https://api.github.com/users/alliedmodders/repos","events_url":"https://api.github.com/users/alliedmodders/events{/privacy}","received_events_url":"https://api.github.com/users/alliedmodders/received_events","type":"Organization","site_admin":false},"repo":{"id":20145274,"name":"sourcemod","full_name":"alliedmodders/sourcemod","owner":{"login":"alliedmodders","id":6601917,"avatar_url":"https://avatars.githubusercontent.com/u/6601917?v=3","gravatar_id":"","url":"https://api.github.com/users/alliedmodders","html_url":"https://github.com/alliedmodders","followers_url":"https://api.github.com/users/alliedmodders/followers","following_url":"https://api.github.com/users/alliedmodders/following{/other_user}","gists_url":"https://api.github.com/users/alliedmodders/gists{/gist_id}","starred_url":"https://api.github.com/users/alliedmodders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alliedmodders/subscriptions","organizations_url":"https://api.github.com/users/alliedmodders/orgs","repos_url":"https://api.github.com/users/alliedmodders/repos","events_url":"https://api.github.com/users/alliedmodders/events{/privacy}","received_events_url":"https://api.github.com/users/alliedmodders/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alliedmodders/sourcemod","description":"SourceMod - Source Engine Scripting and Administration","fork":false,"url":"https://api.github.com/repos/alliedmodders/sourcemod","forks_url":"https://api.github.com/repos/alliedmodders/sourcemod/forks","keys_url":"https://api.github.com/repos/alliedmodders/sourcemod/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alliedmodders/sourcemod/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alliedmodders/sourcemod/teams","hooks_url":"https://api.github.com/repos/alliedmodders/sourcemod/hooks","issue_events_url":"https://api.github.com/repos/alliedmodders/sourcemod/issues/events{/number}","events_url":"https://api.github.com/repos/alliedmodders/sourcemod/events","assignees_url":"https://api.github.com/repos/alliedmodders/sourcemod/assignees{/user}","branches_url":"https://api.github.com/repos/alliedmodders/sourcemod/branches{/branch}","tags_url":"https://api.github.com/repos/alliedmodders/sourcemod/tags","blobs_url":"https://api.github.com/repos/alliedmodders/sourcemod/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alliedmodders/sourcemod/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alliedmodders/sourcemod/git/refs{/sha}","trees_url":"https://api.github.com/repos/alliedmodders/sourcemod/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alliedmodders/sourcemod/statuses/{sha}","languages_url":"https://api.github.com/repos/alliedmodders/sourcemod/languages","stargazers_url":"https://api.github.com/repos/alliedmodders/sourcemod/stargazers","contributors_url":"https://api.github.com/repos/alliedmodders/sourcemod/contributors","subscribers_url":"https://api.github.com/repos/alliedmodders/sourcemod/subscribers","subscription_url":"https://api.github.com/repos/alliedmodders/sourcemod/subscription","commits_url":"https://api.github.com/repos/alliedmodders/sourcemod/commits{/sha}","git_commits_url":"https://api.github.com/repos/alliedmodders/sourcemod/git/commits{/sha}","comments_url":"https://api.github.com/repos/alliedmodders/sourcemod/comments{/number}","issue_comment_url":"https://api.github.com/repos/alliedmodders/sourcemod/issues/comments{/number}","contents_url":"https://api.github.com/repos/alliedmodders/sourcemod/contents/{+path}","compare_url":"https://api.github.com/repos/alliedmodders/sourcemod/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alliedmodders/sourcemod/merges","archive_url":"https://api.github.com/repos/alliedmodders/sourcemod/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alliedmodders/sourcemod/downloads","issues_url":"https://api.github.com/repos/alliedmodders/sourcemod/issues{/number}","pulls_url":"https://api.github.com/repos/alliedmodders/sourcemod/pulls{/number}","milestones_url":"https://api.github.com/repos/alliedmodders/sourcemod/milestones{/number}","notifications_url":"https://api.github.com/repos/alliedmodders/sourcemod/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alliedmodders/sourcemod/labels{/name}","releases_url":"https://api.github.com/repos/alliedmodders/sourcemod/releases{/id}","created_at":"2014-05-25T02:58:39Z","updated_at":"2015-02-25T01:20:37Z","pushed_at":"2015-02-26T06:00:33Z","git_url":"git://github.com/alliedmodders/sourcemod.git","ssh_url":"git@github.com:alliedmodders/sourcemod.git","clone_url":"https://github.com/alliedmodders/sourcemod.git","svn_url":"https://github.com/alliedmodders/sourcemod","homepage":"http://www.sourcemod.net/","size":49540,"stargazers_count":95,"watchers_count":95,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":39,"mirror_url":null,"open_issues_count":17,"forks":39,"open_issues":17,"watchers":95,"default_branch":"master"}},"base":{"label":"alliedmodders:rm-interpreter","ref":"rm-interpreter","sha":"acf6dcac86041c9ea79e9bce594da67376dfb466","user":{"login":"alliedmodders","id":6601917,"avatar_url":"https://avatars.githubusercontent.com/u/6601917?v=3","gravatar_id":"","url":"https://api.github.com/users/alliedmodders","html_url":"https://github.com/alliedmodders","followers_url":"https://api.github.com/users/alliedmodders/followers","following_url":"https://api.github.com/users/alliedmodders/following{/other_user}","gists_url":"https://api.github.com/users/alliedmodders/gists{/gist_id}","starred_url":"https://api.github.com/users/alliedmodders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alliedmodders/subscriptions","organizations_url":"https://api.github.com/users/alliedmodders/orgs","repos_url":"https://api.github.com/users/alliedmodders/repos","events_url":"https://api.github.com/users/alliedmodders/events{/privacy}","received_events_url":"https://api.github.com/users/alliedmodders/received_events","type":"Organization","site_admin":false},"repo":{"id":20145274,"name":"sourcemod","full_name":"alliedmodders/sourcemod","owner":{"login":"alliedmodders","id":6601917,"avatar_url":"https://avatars.githubusercontent.com/u/6601917?v=3","gravatar_id":"","url":"https://api.github.com/users/alliedmodders","html_url":"https://github.com/alliedmodders","followers_url":"https://api.github.com/users/alliedmodders/followers","following_url":"https://api.github.com/users/alliedmodders/following{/other_user}","gists_url":"https://api.github.com/users/alliedmodders/gists{/gist_id}","starred_url":"https://api.github.com/users/alliedmodders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alliedmodders/subscriptions","organizations_url":"https://api.github.com/users/alliedmodders/orgs","repos_url":"https://api.github.com/users/alliedmodders/repos","events_url":"https://api.github.com/users/alliedmodders/events{/privacy}","received_events_url":"https://api.github.com/users/alliedmodders/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alliedmodders/sourcemod","description":"SourceMod - Source Engine Scripting and Administration","fork":false,"url":"https://api.github.com/repos/alliedmodders/sourcemod","forks_url":"https://api.github.com/repos/alliedmodders/sourcemod/forks","keys_url":"https://api.github.com/repos/alliedmodders/sourcemod/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alliedmodders/sourcemod/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alliedmodders/sourcemod/teams","hooks_url":"https://api.github.com/repos/alliedmodders/sourcemod/hooks","issue_events_url":"https://api.github.com/repos/alliedmodders/sourcemod/issues/events{/number}","events_url":"https://api.github.com/repos/alliedmodders/sourcemod/events","assignees_url":"https://api.github.com/repos/alliedmodders/sourcemod/assignees{/user}","branches_url":"https://api.github.com/repos/alliedmodders/sourcemod/branches{/branch}","tags_url":"https://api.github.com/repos/alliedmodders/sourcemod/tags","blobs_url":"https://api.github.com/repos/alliedmodders/sourcemod/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alliedmodders/sourcemod/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alliedmodders/sourcemod/git/refs{/sha}","trees_url":"https://api.github.com/repos/alliedmodders/sourcemod/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alliedmodders/sourcemod/statuses/{sha}","languages_url":"https://api.github.com/repos/alliedmodders/sourcemod/languages","stargazers_url":"https://api.github.com/repos/alliedmodders/sourcemod/stargazers","contributors_url":"https://api.github.com/repos/alliedmodders/sourcemod/contributors","subscribers_url":"https://api.github.com/repos/alliedmodders/sourcemod/subscribers","subscription_url":"https://api.github.com/repos/alliedmodders/sourcemod/subscription","commits_url":"https://api.github.com/repos/alliedmodders/sourcemod/commits{/sha}","git_commits_url":"https://api.github.com/repos/alliedmodders/sourcemod/git/commits{/sha}","comments_url":"https://api.github.com/repos/alliedmodders/sourcemod/comments{/number}","issue_comment_url":"https://api.github.com/repos/alliedmodders/sourcemod/issues/comments{/number}","contents_url":"https://api.github.com/repos/alliedmodders/sourcemod/contents/{+path}","compare_url":"https://api.github.com/repos/alliedmodders/sourcemod/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alliedmodders/sourcemod/merges","archive_url":"https://api.github.com/repos/alliedmodders/sourcemod/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alliedmodders/sourcemod/downloads","issues_url":"https://api.github.com/repos/alliedmodders/sourcemod/issues{/number}","pulls_url":"https://api.github.com/repos/alliedmodders/sourcemod/pulls{/number}","milestones_url":"https://api.github.com/repos/alliedmodders/sourcemod/milestones{/number}","notifications_url":"https://api.github.com/repos/alliedmodders/sourcemod/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alliedmodders/sourcemod/labels{/name}","releases_url":"https://api.github.com/repos/alliedmodders/sourcemod/releases{/id}","created_at":"2014-05-25T02:58:39Z","updated_at":"2015-02-25T01:20:37Z","pushed_at":"2015-02-26T06:00:33Z","git_url":"git://github.com/alliedmodders/sourcemod.git","ssh_url":"git@github.com:alliedmodders/sourcemod.git","clone_url":"https://github.com/alliedmodders/sourcemod.git","svn_url":"https://github.com/alliedmodders/sourcemod","homepage":"http://www.sourcemod.net/","size":49540,"stargazers_count":95,"watchers_count":95,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":39,"mirror_url":null,"open_issues_count":17,"forks":39,"open_issues":17,"watchers":95,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alliedmodders/sourcemod/pulls/284"},"html":{"href":"https://github.com/alliedmodders/sourcemod/pull/284"},"issue":{"href":"https://api.github.com/repos/alliedmodders/sourcemod/issues/284"},"comments":{"href":"https://api.github.com/repos/alliedmodders/sourcemod/issues/284/comments"},"review_comments":{"href":"https://api.github.com/repos/alliedmodders/sourcemod/pulls/284/comments"},"review_comment":{"href":"https://api.github.com/repos/alliedmodders/sourcemod/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alliedmodders/sourcemod/pulls/284/commits"},"statuses":{"href":"https://api.github.com/repos/alliedmodders/sourcemod/statuses/7d38429632c1c0c7fa1e919dbef83cbc7e47260a"}}}}