René's URL Explorer Experiment


Title: Diff.blobToBuffer crashes the node process if given a file that contains null characters · Issue #965 · nodegit/nodegit · GitHub

Open Graph Title: Diff.blobToBuffer crashes the node process if given a file that contains null characters · Issue #965 · nodegit/nodegit

X Title: Diff.blobToBuffer crashes the node process if given a file that contains null characters · Issue #965 · nodegit/nodegit

Description: I was using nodegit to grab some diffs out of a repo, and when it hit a Visio file that was in there it would crash and die. The Visio file was big enough and contained null characters in the right places such that it exposed a bug in no...

Open Graph Description: I was using nodegit to grab some diffs out of a repo, and when it hit a Visio file that was in there it would crash and die. The Visio file was big enough and contained null characters in the right...

X Description: I was using nodegit to grab some diffs out of a repo, and when it hit a Visio file that was in there it would crash and die. The Visio file was big enough and contained null characters in the right...

Opengraph URL: https://github.com/nodegit/nodegit/issues/965

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Diff.blobToBuffer crashes the node process if given a file that contains null characters","articleBody":"I was using nodegit to grab some diffs out of a repo, and when it hit a Visio file that was in there it would crash and die.\n\nThe Visio file was big enough and contained null characters in the right places such that it exposed a bug in nodegit that was causing libgit2 to throw a memory access violation error.\n\nHere's some code that creates a new repo, writes out a file, tries to do a diff, and reproduces the issue:\n\n``` js\nvar fs = require('fs');\nvar path = require('path');\n\nvar rimraf = require('rimraf');\nvar git = require('nodegit');\n\nvar repoPath = 'C:\\\\blobToDiff-test-repo';\nvar testFilePath = \"test.txt\";\nvar testFileFullPath = path.join(repoPath, testFilePath);\n\nrimraf(repoPath, function(err) {\n    if (err) {\n        throw err;\n    }\n\n    console.log(\"rimraf \" + repoPath + \" successful\");\n\n    fs.mkdir(repoPath, function(err) {\n        if (err) {\n            throw err;\n        }\n\n        console.log(\"mkdir \" + repoPath + \" successful\");\n\n        var repository;\n        git.Repository.init(repoPath, 0)\n            .then(\n                function(repository_) {\n                    repository = repository_;\n                    console.log(\"repo successfully inited\");\n                    return repository.index();\n                }\n            )\n            .then(\n                function(index) {\n                    return new Promise(\n                        function(resolve, reject) {\n                            var testFileContent = \"Initial file content.\";\n\n                            fs.writeFile(testFileFullPath, testFileContent, function(err) {\n                                if (err) {\n                                    reject(err);\n                                    return;\n                                }\n\n                                index.addByPath(testFilePath);\n                                index.write();\n                                resolve(index.writeTree());\n                            });\n                        }\n                    );\n                }\n            )\n            .then(\n                function() {\n                    console.log(\"file staged successfully\");\n                    var signature = git.Signature.default(repository);\n                    return repository.createCommitOnHead([], signature, signature, \"Initial commit.\");\n                }\n            )\n            .then(\n                function(oid) {\n                    console.log(\"commit successfully made: \" + oid.toString());\n                    return repository.getCommit(oid);\n                }\n            )\n            .then(\n                function(commit) {\n                    console.log(\"commit object successfully gotten\");\n                    return commit.getTree();\n                }\n            )\n            .then(\n                function(tree) {\n                    console.log(\"commit tree successfully gotten\");\n                    return tree.entryByPath(testFilePath);\n                }\n            )\n            .then(\n                function(treeEntry) {\n                    console.log(\"tree entry successfully gotten\");\n                    return repository.getBlob(treeEntry.sha());\n                }\n            )\n            .then(\n                function(blob) {\n                    console.log(\"blob successfully gotten: \" + blob.id());\n\n                    //var testDiffContent = new Buffer(\"abc123\");\n                    var testDiffContent = new Buffer(1362240);\n                    var i;\n\n                    for (i = 0; i \u003c testDiffContent.length/2; i++) {\n                        testDiffContent.write('a', i);\n                    }\n                    for (i = Math.floor(testDiffContent.length/2); i \u003c testDiffContent.length; i++) {\n                        testDiffContent.write('\\0', i);\n                    }\n\n                    console.log(\"about to generate diff\");\n                    console.log();\n\n                    return git.Diff.blobToBuffer(\n                        blob, testFilePath,\n                        testDiffContent, testFilePath, new git.DiffOptions(),\n                        null,\n                        function() {\n                            console.log(\"binary file detected.\");\n                        },\n                        function(diffDelta, diffHunk) {\n                            console.log(\n                                \"diff\" + \" \" + diffDelta.oldFile().path() + \" \" +\n                                diffDelta.newFile().path(),\n                                diffHunk.header().trim()\n                            );\n                        },\n                        function(diffDelta, diffHunk, diffLine) {\n                            console.log(\n                                String.fromCharCode(diffLine.origin()) + diffLine.content()\n                            );\n                        }\n                    )\n                }\n            )\n            .then(\n                function() {\n                    console.log();\n                    console.log(\"program completed successfully\");\n                }\n            )\n            .catch(\n                function(e) {\n                    console.error(e);\n                }\n            )\n        ;\n    })\n});\n```\n\nThis is the output of the program when it fails:\n\n```\nrimraf C:\\blobToDiff-test-repo successful\nmkdir C:\\blobToDiff-test-repo successful\nrepo successfully inited\nfile staged successfully\ncommit successfully made: bb52bb49f1e0e3d5dfe5481675f0a859613f3aee\ncommit object successfully gotten\ncommit tree successfully gotten\ntree entry successfully gotten\nblob successfully gotten: b51b03824b122391a34d89c3c6afb61f2483333e\nabout to generate diff\n\n\nProcess finished with exit code -1073741819 (0xC0000005)\n```\n\nFor whatever its worth I'm running Windows 10 x64 and nodejs 4.2.3 x64 along with the nodegit 0.11.9.\n\nThese lines from nodegit's `diff.cc` file seem to be the cause of the issue:\n\n``` cpp\nString::Utf8Value buffer(info[2]-\u003eToString());\n  from_buffer = (const char *) strdup(*buffer);\n  }\n  else {\n    from_buffer = 0;\n  }\n// end convert_from_v8 block\n  baton-\u003ebuffer = from_buffer;\n// start convert_from_v8 block\n  size_t from_buffer_len;\n    if (info[3]-\u003eIsNumber()) {\n  from_buffer_len = (size_t)   info[3]-\u003eToNumber()-\u003eValue();\n  }\n  else {\n    from_buffer_len = 0;\n  }\n// end convert_from_v8 block\n  baton-\u003ebuffer_len = from_buffer_len;\n```\n\nThey are using the `strdup` function, which is expecting a C-style string, which is terminated by a null. The strings we get back from nodejs are not null-terminated, nor do we want them to be, since in this case we're using the nodejs string to pass the contents of an entire file to libgit2, and that file may very well contain null characters in it depending on the file type.\n\nThe `strdup`, combined with trusting the `buffer_len` that's passed in as being accurate to the size of the buffer we have, causes libgit2 to try to read into invalid memory space, and thus crashes the program.\n\nI'm not 100% sure of what the best way to solve this is, but I have a guess which I will send in a pull request in a few minutes.\n","author":{"url":"https://github.com/tylerchurch","@type":"Person","name":"tylerchurch"},"datePublished":"2016-03-24T02:28:46.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/965/nodegit/issues/965"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:590d9316-1a40-9fb0-09c2-4ec89eb80c17
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id87C6:39FF61:2FC9D9C:3DD705C:6974DFFC
html-safe-nonce28089d81e9f5b1fe6b21220d2ef58a2da291dd2ce74754876b56632ee93ee6a5
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4N0M2OjM5RkY2MToyRkM5RDlDOjNERDcwNUM6Njk3NERGRkMiLCJ2aXNpdG9yX2lkIjoiMjM5NDA2MDgyNzQ5Mzk4MjIwNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmaca66734c2d06ce6f39a42552d57f1e4cfc7843affa35b6838006d6b1c3bb2c577
hovercard-subject-tagissue:143129662
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodegit/nodegit/965/issue_layout
twitter:imagehttps://opengraph.githubassets.com/f026b4962679406af88c6fc8e1683ef5a3feb17148db20cc75a0d4a311d60781/nodegit/nodegit/issues/965
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/f026b4962679406af88c6fc8e1683ef5a3feb17148db20cc75a0d4a311d60781/nodegit/nodegit/issues/965
og:image:altI was using nodegit to grab some diffs out of a repo, and when it hit a Visio file that was in there it would crash and die. The Visio file was big enough and contained null characters in the right...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernametylerchurch
hostnamegithub.com
expected-hostnamegithub.com
None4a4bf5f4e28041a9d2e5c107d7d20b78b4294ba261cab243b28167c16a623a1f
turbo-cache-controlno-preview
go-importgithub.com/nodegit/nodegit git https://github.com/nodegit/nodegit.git
octolytics-dimension-user_id657068
octolytics-dimension-user_loginnodegit
octolytics-dimension-repository_id1383170
octolytics-dimension-repository_nwonodegit/nodegit
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1383170
octolytics-dimension-repository_network_root_nwonodegit/nodegit
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release488b30e96dfd057fbbe44c6665ccbc030b729dde
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/nodegit/nodegit/issues/965#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodegit%2Fnodegit%2Fissues%2F965
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodegit%2Fnodegit%2Fissues%2F965
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=nodegit%2Fnodegit
Reloadhttps://github.com/nodegit/nodegit/issues/965
Reloadhttps://github.com/nodegit/nodegit/issues/965
Reloadhttps://github.com/nodegit/nodegit/issues/965
nodegit https://github.com/nodegit
nodegithttps://github.com/nodegit/nodegit
Notifications https://github.com/login?return_to=%2Fnodegit%2Fnodegit
Fork 697 https://github.com/login?return_to=%2Fnodegit%2Fnodegit
Star 5.8k https://github.com/login?return_to=%2Fnodegit%2Fnodegit
Code https://github.com/nodegit/nodegit
Issues 343 https://github.com/nodegit/nodegit/issues
Pull requests 19 https://github.com/nodegit/nodegit/pulls
Actions https://github.com/nodegit/nodegit/actions
Projects 0 https://github.com/nodegit/nodegit/projects
Security 0 https://github.com/nodegit/nodegit/security
Insights https://github.com/nodegit/nodegit/pulse
Code https://github.com/nodegit/nodegit
Issues https://github.com/nodegit/nodegit/issues
Pull requests https://github.com/nodegit/nodegit/pulls
Actions https://github.com/nodegit/nodegit/actions
Projects https://github.com/nodegit/nodegit/projects
Security https://github.com/nodegit/nodegit/security
Insights https://github.com/nodegit/nodegit/pulse
New issuehttps://github.com/login?return_to=https://github.com/nodegit/nodegit/issues/965
New issuehttps://github.com/login?return_to=https://github.com/nodegit/nodegit/issues/965
Diff.blobToBuffer crashes the node process if given a file that contains null charactershttps://github.com/nodegit/nodegit/issues/965#top
https://github.com/tylerchurch
https://github.com/tylerchurch
tylerchurchhttps://github.com/tylerchurch
on Mar 24, 2016https://github.com/nodegit/nodegit/issues/965#issue-143129662
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.