Document props: fix null terminated strings from MuPDF#12468
Closed
hius07 wants to merge 1 commit into
Closed
Conversation
Comment on lines
+178
to
+179
| elseif str:sub(-1) == "\0" then | ||
| return str:sub(1, -2) |
Member
There was a problem hiding this comment.
This fill like papering over a bug that should be fixed where that string is created.
Member
Author
There was a problem hiding this comment.
Member
There was a problem hiding this comment.
/**
Retrieve document meta data strings.
doc: The document to query.
key: Which meta data key to retrieve...
[…]
buf: The buffer to hold the results (a nul-terminated UTF-8
string).
size: Size of 'buf'.
Returns the number of bytes need to store the string plus terminator
(will be larger than 'size' if the output was truncated), or -1 if the
key is not recognized or found.
*/
int fz_lookup_metadata(fz_context *ctx, fz_document *doc, const char *key, char *buf, int size);So can you test with this version:
local function getMetadataInfo(doc, info)
local bufsize = 255
local buf = ffi.new("char[?]", bufsize)
local res = M.fz_lookup_metadata(context(), doc, info, buf, bufsize)
if res > bufsize then
bufsize = res
buf = ffi.new("char[?]", bufsize)
res = M.fz_lookup_metadata(context(), doc, info, buf, bufsize)
end
if res > 1 then
return ffi.string(buf, res - 1)
end
return ""
end
Frenzie
pushed a commit
to koreader/koreader-base
that referenced
this pull request
Sep 5, 2024
Don't create Lua strings with an embedded null terminator. Cf. koreader/koreader#12468.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #12462.
For reference:
https://github.com/koreader/koreader-base/blob/ecf6bc70c8f662ab00e819885b74a937eb59d332/ffi/mupdf.lua#L274-L287
This change is