Subject: bug#78184: closed (Re: bug#78184: 30.0.93; ansi-osc-apply-on-region should use end marker)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 31 May 2025 12:24:07 +0000

Your bug report

#78184: 30.0.93; ansi-osc-apply-on-region should use end marker

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
78184: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=78184
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#78184: 30.0.93; ansi-osc-apply-on-region should use end marker
From: Eli Zaretskii <[email-masked]>
To: Matthias Meulien <[email-masked]>
Cc: [email-masked], [email-masked]
Date: Sat, 31 May 2025 15:23:42 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: Matthias Meulien <[email-masked]>
> Date: Sat, 31 May 2025 14:02:24 +0200
> Cc: Troy Brown <[email-masked]>, [email-masked]
> 
> Sorry I don't think I've write access to the source repository. Whats more I've no personnal computer at
> home for an undefined time period...

OK, so I've now installed the patch on the master branch, and I'm
therefore closing this bug.

Subject: 30.0.93; ansi-osc-apply-on-region should use end marker
From: Troy Brown <[email-masked]>
To: [email-masked]
Date: Thu, 1 May 2025 07:47:56 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

I've been running into an issue when using the ANSI OSC compilation
filters, where part way through parsing input, I'll get an "args out
of range" error on the call to `put-text-property`.  I believe this is
because `ansi-osc-apply-on-region` uses `delete-region` and therefore
the buffer can shrink from its original size.  Due to this shrinking,
the use of "end", in the call to `put-text-property` can reside
outside the current bounds of the buffer, causing the error.

Looking at similar functionality in `ansi-color-apply-on-region`, I
noticed that it creates a marker for "end" at the beginning of the
function, avoiding this problem.  I believe the ANSI OSC package
should use a similar approach and create a marker for "end".  It's
also likely that a marker should be used in other functions within the
package, such as `ansi-osc-filter-region`, although
`re-search-forward` doesn't seem to be susceptible to the range issue
that `put-text-property` is.

Currently, I use the following advice to workaround the problem by
ensuring that "end" is a marker before calling the original function:

```emacs
(defun init.el/advice/ansi-osc-apply-on-region (oldfun &rest r)
  (let ((start (car r))
        (end (cadr r)))
    (funcall oldfun start (copy-marker end))))
(advice-add 'ansi-osc-apply-on-region :around
#'init.el/advice/ansi-osc-apply-on-region)
```