bugGNU Octave - Bugs: bug #55984, movfun dangerous test for function...

 
 

bug #55984: movfun dangerous test for function output dimension

Submitter:  Juan Pablo Carbajal <juanpi>
Submitted:  Sat 23 Mar 2019 12:43:05 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Feature Request
Status:  Fixed Assigned to:  juanpi
Originator Name:  juanpi Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 15 Jan 2024 04:59:24 AM UTC, comment #3: 

This does seem like a good idea.  I made Juan's change, with a small adaptation to guarantee a column vector, in this changeset: https://hg.savannah.gnu.org/hgweb/octave/rev/50146e3265e0.  I gave credit to Juan by checking the change in under his name.

Marking bug as Fixed and closing report.

Rik <rik5>
Group administrator
Sun 04 Oct 2020 03:43:13 PM UTC, comment #2: 

The issue is that the code assumes that all zeros is a valid input for the function.

The following example shows the failure


function y = bad_func (x)
  if all (x != 0)
    y = sum (x);
  endif
endfunction

movfun(@bad_func,rand(1,100),3)
error: 'y' undefined near line 1, column 1
error: called from
    bad_func at line 5 column 1
    movfun at line 259 column 11


The function is not defined for the input that we are using to recover the output dimension.
A better check is to use the input that the user provided. If there is a failure then is an user error and not due to an assumption in the code.

Here are the changes to be done on movfun.m from default branch (491433ba8612) to implement the safer "check"


259c259
<   tmp     = fcn (zeros (length (win), 1));  # output for window
---
>   tmp     = fcn (x(1:length(win)));  # output for window


After this changes the previous examples runs, and the error is recovered when the user input is invalid


movfun(@bad_func,zeros(1,100),3)
error: 'y' undefined near line 1, column 1
error: called from
    bad_func at line 5 column 1
    movfun at line 259 column 11


I cannot think of a test to provide a better error message in that case. I guess it is up to the programmer of bad_func.


Juan Pablo Carbajal <juanpi>
Group Member
Tue 29 Sep 2020 05:44:00 PM UTC, comment #1: 

Can you provide an example function and call to movfun that demonstrates the potential failure?

John W. Eaton <jwe>
Group administrator
Sat 23 Mar 2019 12:43:05 AM UTC, original submission:  

Line 255 is meant to recover the output dimension of the function to evaluate. The input argument is set to all zeros.
This is dangerous, and incorrect, the function might not be defined at zero.
It is better to pass an arbitrary subset of the given inputs, if this causes an error is de to invalid inputs to the function.


Juan Pablo Carbajal <juanpi>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by juanpi (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-01-15 rik5 StatusNeed Info Fixed
        Open/ClosedOpen Closed
    2020-09-29 jwe Severity4 - Important 3 - Normal
        StatusIn Progress Need Info
    2019-03-23 juanpi Summarymovfun dangerous test for fucntion output dimension movfun dangerous test for function output dimension

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code