Skip to content

Document props: fix null terminated strings from MuPDF#12468

Closed
hius07 wants to merge 1 commit into
koreader:masterfrom
hius07:doc-props
Closed

Document props: fix null terminated strings from MuPDF#12468
hius07 wants to merge 1 commit into
koreader:masterfrom
hius07:doc-props

Conversation

@hius07

@hius07 hius07 commented Sep 5, 2024

Copy link
Copy Markdown
Member

Comment on lines +178 to +179
elseif str:sub(-1) == "\0" then
return str:sub(1, -2)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fill like papering over a bug that should be fixed where that string is created.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
	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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that works.

@hius07 hius07 closed this Sep 5, 2024
@hius07 hius07 deleted the doc-props branch September 5, 2024 06:46
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exports to Html do not have extension

2 participants