Closed Bug 317383 Opened 19 years ago Closed 18 years ago

CheckLoadURI doesn't throw an exception when setting img.src from script

Categories

(Core :: Security, defect)

1.7 Branch
x86
Linux
defect
Not set
normal

Tracking

()

VERIFIED INVALID

People

(Reporter: znaeff, Assigned: dveditz)

Details

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; ru-RU; rv:1.7.10) Gecko/20050907 ASPLinux/1.7.10-1.3.1asp
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; ru-RU; rv:1.7.12) Gecko/20050920 Firefox/1.0.7

Setting CheckLoadURI to true doesn't generate an exception when I'm trying to load local image as Image.src. So impossible to handle CheckLoadURI setting and inform user about it.


Reproducible: Always

Steps to Reproduce:
1. Write a script with code:
SomeFileSrc = '/home/user/pictures/bla-bla-bla.jpg';
LocalImg = new Image();
try{
 LocalImg.src = 'file://' + SomeFileSrc;
}catch(e){
 alert('Got it');
}

2. Run this script from page.

Actual Results:  
LocalImg.complete is set to true immediately.
LocalImg.src is equal to string 'file://' + SomeFileSrc.
No alerts appear at all, just scurity notification message in JavaScript console.


Expected Results:  
Browser should generate an exception, so alert should appear.


The same result is under Windows and in the Mozilla 1.7.* under Linux and Windows.
Assignee: nobody → dveditz
Product: Firefox → Core
QA Contact: firefox → toolkit
Summary: CheckLoadURI doesn't generate an exception on file:// images. → CheckLoadURI doesn't throw an exception when setting img.src from script
Version: unspecified → 1.7 Branch
I don't think we want to throw here (since this _does_ change the "src" attribute and all)...
Yeah, I don't really think we want to throw either. Setting .src is the same as calling setAttribute, and that should clearly not throw.
Status: UNCONFIRMED → RESOLVED
Closed: 18 years ago
Resolution: --- → INVALID
(In reply to comment #2)
> Yeah, I don't really think we want to throw either. Setting .src is the same as
> calling setAttribute, and that should clearly not throw.

Well, but _actually_ result is not achieved.
I cannot operate with LocalImg height and width, for example, and I'm not informed about it.
While I agree, it is a tricky situation. I guess we could throw just for SetSrc, but not for SetAttribute, i'm not exited about the two functions behaving differently.
Actually, what we should do is that we should fire an error event. Or do we already do that?
We fire an error event in this case, yes.
Then that should be enough IMO. We are successful in setting the attribute and so should not throw. If you're interested in if we succeed to load or not, then attach event listeners.
(In reply to comment #7)
> Then that should be enough IMO. We are successful in setting the attribute and
> so should not throw. If you're interested in if we succeed to load or not, then
> attach event listeners.

Sure, I did this. But it's not so trivial sutuation when neither success listener  nor fault listener is called. So it's not easy to inform user about impossibility to load local picture.
> But it's not so trivial sutuation when neither success listener  nor fault
> listener is called.

What build are you testing?  Note bug 269125 was fixed on the Gecko 1.9 trunk after 1.8 branched off, so onerror only fires in trunk builds in this case.
The error listener should be called, no?
(In reply to comment #9)
> What build are you testing?

For example 
Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.8) Gecko/20051111 Firefox/1.5

(In reply to comment #10)
> The error listener should be called, no?

No. Absolutely.
I set next listeners:
----------
LocalImg = new Image();
LocalImg.onerror = LocalImgOnError;
LocalImg.onload = LocalImgOnLoad;
----------
And neither LocalImgOnError nor LocalImgOnLoad are not called.

To catch this situation I need to do something like this:
----------
oldImgSrc = LocalImg.src;
newImgSrc = 'file://' + SomeFileSrc;
try{
 LocalImg.src = newImgSrc;
 if(!LocalImg.complete || (LocalImg.src == oldImgSrc))
  throw new Error('Not loaded ' + newImgSrc);
}catch(e){
 ...
}
----------
So that problem is fixed so that LocalImgOnError is called. However it was fixed too late to make FF 1.5.

We should consider porting bug 269125 to the 1.8.1 branch so that it gets fixed in FF 2.
(In reply to comment #12)
> So that problem is fixed so that LocalImgOnError is called. However it was
> fixed too late to make FF 1.5.
> 
> We should consider porting bug 269125 to the 1.8.1 branch so that it gets fixed
> in FF 2.

Well! Thanks a lot.
 
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.