Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 72d0024

Browse files
committed
attr_file: Do not assume ODB data is NULL-terminated
That's a bad assumption to make, even though right now it holds (because of the way we've implemented decompression of packfiles), this may change in the future, given that ODB objects can be binary data. Furthermore, the ODB object can return a NULL pointer if the object is empty. Copying the NULL pointer to the strbuf lets us handle it like an empty string. Again, the NULL pointer is valid behavior because you're supposed to check the *size* of the object before working on it.
1 parent 92e0b67 commit 72d0024

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/attr_file.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ int git_attr_file__load(
103103
int error = 0;
104104
git_blob *blob = NULL;
105105
git_buf content = GIT_BUF_INIT;
106-
const char *data = NULL;
107106
git_attr_file *file;
108107
struct stat st;
109108

@@ -120,7 +119,9 @@ int git_attr_file__load(
120119
(error = git_blob_lookup(&blob, repo, &id)) < 0)
121120
return error;
122121

123-
data = git_blob_rawcontent(blob);
122+
/* Do not assume that data straight from the ODB is NULL-terminated;
123+
* copy the contents of a file to a buffer to work on */
124+
git_buf_put(&content, git_blob_rawcontent(blob), git_blob_rawsize(blob));
124125
break;
125126
}
126127
case GIT_ATTR_FILE__FROM_FILE: {
@@ -143,7 +144,6 @@ int git_attr_file__load(
143144
if (error < 0)
144145
return GIT_ENOTFOUND;
145146

146-
data = content.ptr;
147147
break;
148148
}
149149
default:
@@ -154,7 +154,7 @@ int git_attr_file__load(
154154
if ((error = git_attr_file__new(&file, entry, source)) < 0)
155155
goto cleanup;
156156

157-
if (parser && (error = parser(repo, file, data)) < 0) {
157+
if (parser && (error = parser(repo, file, git_buf_cstr(&content))) < 0) {
158158
git_attr_file__free(file);
159159
goto cleanup;
160160
}

0 commit comments

Comments
 (0)