Acronym lookup fails #4

Closed
opened 2022-07-23 10:53:01 +00:00 by fleimgruber · 16 comments
fleimgruber commented 2022-07-23 10:53:01 +00:00 (Migrated from github.com)

Emacs 28.1
org 9.5.2
org-glossary master

With glossary definition

* Acronyms
- UAF :: Use After Free

Pressing RET on a reference of UAF (in a file zig.org, using #+glossary_sources with appropriate org-glossary-collection-root) gives the backtrace at the end. I debugged this briefly and found that b2b53e8246/org-glossary.el (L1841) evaluates to:

Result: (:key "UAF" :key-plural "UAFs" :key-nonce 3 :term "UAF" :term-plural "UAFs" :alias-for nil :type acronym :category nil :value (#("Use After Free\n" 0 15 (:parent nil))) :definition-file #<buffer zig.org> :definition-pos 14 :extracted nil :uses nil)

which looks suspicious to me where :definition-file #<buffer zig.org> the referring file (zig.org) is confused with the definitions file (glossary.org)?

Debugger entered--Lisp error: (wrong-type-argument stringp #<buffer zig.org>)
  file-name-extension(#<buffer zig.org>)
  (or (file-name-extension filename) "")
  (downcase (or (file-name-extension filename) ""))
  (let* ((ext (downcase (or (file-name-extension filename) ""))) (file (expand-file-name filename)) (process-connection-type nil) (ex (let* ((--cl-var-- dirvish-open-with-programs) (args nil) (exts nil) (cmd nil) (--cl-flag-- t) --cl-var--) (while (and (consp --cl-var--) (progn (setq args ... exts ... cmd ...) (setq --cl-flag-- ...))) (setq --cl-var-- (cdr --cl-var--))) --cl-var--))) (cond (ex (and (and (boundp 'recentf-mode) recentf-mode) (add-to-list 'recentf-list file)) (apply #'start-process "" nil "nohup" (cl-substitute file "%f" ex :test 'string=))) (t (let* ((dv (and t (let* ... val)))) (if dv (funcall (progn (or ... ...) (aref dv 13)) dv) nil)) (funcall fn file wildcard))))
  dirvish-find-file-ad(#<subr find-file> #<buffer zig.org>)
  apply(dirvish-find-file-ad #<subr find-file> #<buffer zig.org>)
  find-file(#<buffer zig.org>)
  (let ((def-file (plist-get term-entry :definition-file))) (if (bufferp def-file) (switch-to-buffer def-file)) (find-file def-file))
  (progn (let* ((aliased-term (and t (org-glossary--quicklookup (string-trim (org-element-interpret-data ...)))))) (if aliased-term (setq term-entry aliased-term) nil)) (let ((def-file (plist-get term-entry :definition-file))) (if (bufferp def-file) (switch-to-buffer def-file)) (find-file def-file)) (goto-char (plist-get term-entry :definition-pos)) term-entry)
  (if term-entry (progn (let* ((aliased-term (and t (org-glossary--quicklookup (string-trim ...))))) (if aliased-term (setq term-entry aliased-term) nil)) (let ((def-file (plist-get term-entry :definition-file))) (if (bufferp def-file) (switch-to-buffer def-file)) (find-file def-file)) (goto-char (plist-get term-entry :definition-pos)) term-entry) nil)
  (let* ((term-entry (and t (if (consp term-ref) term-ref (or (org-glossary--quicklookup (or ... ...)) (org-glossary--select-term org-glossary--terms)))))) (if term-entry (progn (let* ((aliased-term (and t (org-glossary--quicklookup ...)))) (if aliased-term (setq term-entry aliased-term) nil)) (let ((def-file (plist-get term-entry :definition-file))) (if (bufferp def-file) (switch-to-buffer def-file)) (find-file def-file)) (goto-char (plist-get term-entry :definition-pos)) term-entry) nil))
  org-glossary-goto-term-definition()
  funcall-interactively(org-glossary-goto-term-definition)
  command-execute(org-glossary-goto-term-definition)
Emacs 28.1 org 9.5.2 org-glossary master With glossary definition ``` * Acronyms - UAF :: Use After Free ``` Pressing RET on a reference of UAF (in a file `zig.org`, using `#+glossary_sources` with appropriate `org-glossary-collection-root`) gives the backtrace at the end. I debugged this briefly and found that https://github.com/tecosaur/org-glossary/blob/b2b53e82468feda2d0b68d3b30bdbe4c06dc815d/org-glossary.el#L1841 evaluates to: ``` Result: (:key "UAF" :key-plural "UAFs" :key-nonce 3 :term "UAF" :term-plural "UAFs" :alias-for nil :type acronym :category nil :value (#("Use After Free\n" 0 15 (:parent nil))) :definition-file #<buffer zig.org> :definition-pos 14 :extracted nil :uses nil) ``` which looks suspicious to me where `:definition-file #<buffer zig.org>` the referring file (zig.org) is confused with the definitions file (glossary.org)? ``` Debugger entered--Lisp error: (wrong-type-argument stringp #<buffer zig.org>) file-name-extension(#<buffer zig.org>) (or (file-name-extension filename) "") (downcase (or (file-name-extension filename) "")) (let* ((ext (downcase (or (file-name-extension filename) ""))) (file (expand-file-name filename)) (process-connection-type nil) (ex (let* ((--cl-var-- dirvish-open-with-programs) (args nil) (exts nil) (cmd nil) (--cl-flag-- t) --cl-var--) (while (and (consp --cl-var--) (progn (setq args ... exts ... cmd ...) (setq --cl-flag-- ...))) (setq --cl-var-- (cdr --cl-var--))) --cl-var--))) (cond (ex (and (and (boundp 'recentf-mode) recentf-mode) (add-to-list 'recentf-list file)) (apply #'start-process "" nil "nohup" (cl-substitute file "%f" ex :test 'string=))) (t (let* ((dv (and t (let* ... val)))) (if dv (funcall (progn (or ... ...) (aref dv 13)) dv) nil)) (funcall fn file wildcard)))) dirvish-find-file-ad(#<subr find-file> #<buffer zig.org>) apply(dirvish-find-file-ad #<subr find-file> #<buffer zig.org>) find-file(#<buffer zig.org>) (let ((def-file (plist-get term-entry :definition-file))) (if (bufferp def-file) (switch-to-buffer def-file)) (find-file def-file)) (progn (let* ((aliased-term (and t (org-glossary--quicklookup (string-trim (org-element-interpret-data ...)))))) (if aliased-term (setq term-entry aliased-term) nil)) (let ((def-file (plist-get term-entry :definition-file))) (if (bufferp def-file) (switch-to-buffer def-file)) (find-file def-file)) (goto-char (plist-get term-entry :definition-pos)) term-entry) (if term-entry (progn (let* ((aliased-term (and t (org-glossary--quicklookup (string-trim ...))))) (if aliased-term (setq term-entry aliased-term) nil)) (let ((def-file (plist-get term-entry :definition-file))) (if (bufferp def-file) (switch-to-buffer def-file)) (find-file def-file)) (goto-char (plist-get term-entry :definition-pos)) term-entry) nil) (let* ((term-entry (and t (if (consp term-ref) term-ref (or (org-glossary--quicklookup (or ... ...)) (org-glossary--select-term org-glossary--terms)))))) (if term-entry (progn (let* ((aliased-term (and t (org-glossary--quicklookup ...)))) (if aliased-term (setq term-entry aliased-term) nil)) (let ((def-file (plist-get term-entry :definition-file))) (if (bufferp def-file) (switch-to-buffer def-file)) (find-file def-file)) (goto-char (plist-get term-entry :definition-pos)) term-entry) nil)) org-glossary-goto-term-definition() funcall-interactively(org-glossary-goto-term-definition) command-execute(org-glossary-goto-term-definition) ```
yantar92 commented 2022-07-23 11:02:13 +00:00 (Migrated from github.com)

I suspect that you didn't save the zig.org buffer. Though such scenario is certainly missed in the code.

I suspect that you didn't save the zig.org buffer. Though such scenario is certainly missed in the code.
fleimgruber commented 2022-07-23 11:23:54 +00:00 (Migrated from github.com)

Double-checked that the buffer was saved. Error remains.

Double-checked that the buffer was saved. Error remains.
tecosaur commented 2022-07-23 16:26:59 +00:00 (Migrated from github.com)

Actually, unsaved/non-file buffers are currently supported. The issue here was a typo misplacing a paren. Fixed in 10399b9d5e.

Actually, unsaved/non-file buffers are currently supported. The issue here was a typo misplacing a paren. Fixed in 10399b9d5ebf9974e5e93fdef17a294cdcd6c197.
fleimgruber commented 2022-07-23 16:51:02 +00:00 (Migrated from github.com)

@tecosaur Thanks for the quick fix. After pulling your fix, after pressing RET on the UAF reference, point jumps to the :ID: ... line of the zig.org header:

:PROPERTIES:
:ID:       4e756c0e-84b2-494a-b6be-5341813c0a82
:END:
#+title: Zig - All Your Codebase Are Belong To Us
#+glossary_sources: glossary.org

but I expected it to jump to the corresponding line in glossary.org.

@tecosaur Thanks for the quick fix. After pulling your fix, after pressing RET on the `UAF` reference, point jumps to the `:ID: ...` line of the `zig.org` header: ``` :PROPERTIES: :ID: 4e756c0e-84b2-494a-b6be-5341813c0a82 :END: #+title: Zig - All Your Codebase Are Belong To Us #+glossary_sources: glossary.org ``` but I expected it to jump to the corresponding line in glossary.org.
tecosaur commented 2022-07-23 16:53:29 +00:00 (Migrated from github.com)

It would be good if you could provide a MWE so I could attempt to reproduce this.

It would be good if you could provide a MWE so I could attempt to reproduce this.
fleimgruber commented 2022-07-23 17:06:49 +00:00 (Migrated from github.com)

glossary.org (in org-glossary-collection-root)

* Acronyms
- UAF :: Use After Free

issue4.org

:PROPERTIES:
:ID:       4e756c0e-84b2-494a-b6be-5341813c0a82
:END:
#+title: Zig - All Your Codebase Are Belong To Us
#+glossary_sources: glossary.org

UAF is no good.
glossary.org (in `org-glossary-collection-root`) ``` * Acronyms - UAF :: Use After Free ``` issue4.org ``` :PROPERTIES: :ID: 4e756c0e-84b2-494a-b6be-5341813c0a82 :END: #+title: Zig - All Your Codebase Are Belong To Us #+glossary_sources: glossary.org UAF is no good. ```
fleimgruber commented 2022-07-23 17:11:05 +00:00 (Migrated from github.com)

As mentioned in my first post, this remains suspect to me :definition-file #<buffer zig.org>. I also noted that I see this in debugging even if I pressed RET on UAF in the issue4.org file.

As mentioned in my first post, this remains suspect to me `:definition-file #<buffer zig.org>`. I also noted that I see this in debugging even if I pressed RET on UAF in the issue4.org file.
tecosaur commented 2022-07-23 17:19:01 +00:00 (Migrated from github.com)

What do you have org-glossary-collection-root set to?

What do you have `org-glossary-collection-root` set to?
fleimgruber commented 2022-07-23 17:25:08 +00:00 (Migrated from github.com)

"/path/to/directory/containing/glossary.org/"

"/path/to/directory/containing/glossary.org/"
tecosaur commented 2022-07-23 17:26:16 +00:00 (Migrated from github.com)

So org-glossary-collection-root is the path to glossary.org and then you have #+glossary_sources: glossary.org ?

So `org-glossary-collection-root` is the path to `glossary.org` and then you have `#+glossary_sources: glossary.org` ?
fleimgruber commented 2022-07-23 17:27:34 +00:00 (Migrated from github.com)

Sorry for the confusion. It is the path to the folder containing glossary.org. It has a trailing slash because of another string concat bug.

Sorry for the confusion. It is the path to the folder containing `glossary.org`. It has a trailing slash because of another string concat bug.
tecosaur commented 2022-07-23 17:27:53 +00:00 (Migrated from github.com)

Ah cool, yep that's alright then.

Ah cool, yep that's alright then.
tecosaur commented 2022-07-23 17:33:27 +00:00 (Migrated from github.com)
Ok, I just attempted to reproduce this without success. https://user-images.githubusercontent.com/20903656/180616339-18d6c1b1-c5d3-49d4-8c71-f37ca0766bb6.mp4
fleimgruber commented 2022-07-23 17:39:25 +00:00 (Migrated from github.com)

Might be a missing cache invalidation? Looking at org-glossary--quicklookup-cache here.

Might be a missing cache invalidation? Looking at `org-glossary--quicklookup-cache` here.
tecosaur commented 2022-12-09 08:23:22 +00:00 (Migrated from github.com)

@fleimgruber let me know if you still experience any issues along these lines.

@fleimgruber let me know if you still experience any issues along these lines.
fleimgruber commented 2022-12-09 09:07:07 +00:00 (Migrated from github.com)

@tecosaur thanks for checking back. As I am still using org-mode <9.6 I will test this more when I upgrade. In case of issues I will reopen.

@tecosaur thanks for checking back. As I am still using org-mode <9.6 I will test this more when I upgrade. In case of issues I will reopen.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: tec/org-glossary#4
No description provided.