Closed Bug 942791 Opened 11 years ago Closed 11 years ago

Non-ASCII file names should be accessible in FTP directory listings regardless of the FEAT/UTF8 support

Categories

(Core Graveyard :: Networking: FTP, defect)

defect
Not set
normal

Tracking

(firefox28 fixed, firefox29 fixed)

RESOLVED FIXED
mozilla29
Tracking Status
firefox28 --- fixed
firefox29 --- fixed

People

(Reporter: emk, Assigned: emk)

References

Details

(Whiteboard: [qa-])

Attachments

(2 files, 2 obsolete files)

See bug 942495.
On Nightly, the issue was not reproduced. Probably because the default encoding is windows-1252 which is has round-trip mapping from/to Unicode.
I confirmed I had to set [Options]-[Content]-[Advanced]-[Fallback Character Encoding] to Japanese to reproduce the issue.
Assignee: nobody → VYV03354
Status: NEW → ASSIGNED
Attachment #8337734 - Flags: review?(honzab.moz)
Summary: Non-ASCII file names should be accessible regardless of the FEAT/UTF8 support → Non-ASCII file names should be accessible in FTP directory listings regardless of the FEAT/UTF8 support
The error recovery in the previous patch didn't work if the sequence contains a partial sequence (such as 0xE3 0x81). The new patch will give up and fallback if the sequence contains an invalid sequence as UTF-8.
Attachment #8337734 - Attachment is obsolete: true
Attachment #8337734 - Flags: review?(honzab.moz)
Attachment #8338498 - Flags: review?(honzab.moz)
Blocks: 943284
The "fix" for bug 427089 is totally broken. It prevented access to files in <ftp://ftp.picosystems.net/> (from bug 942495).
I confirmed this didn't regress bug 427089.
Attachment #8339240 - Flags: review?(michal.novotny)
Comment on attachment 8338498 [details] [diff] [review]
Ensure non-ASCII filenames are accessible in FTP directory listings

Review of attachment 8338498 [details] [diff] [review]:
-----------------------------------------------------------------

Tested with ftp://ftp.picosystems.net/
Still 550 when switched to Shift_JIS, is that expected?

::: netwerk/streamconv/converters/nsIndexedToHTML.cpp
@@ +865,3 @@
>      // Adding trailing slash helps to recognize whether the URL points to a file
>      // or a directory (bug #214405).
> +    if ((type == nsIDirIndex::TYPE_DIRECTORY) &&(loc.Last() != '/')) {

add space after &&

@@ +884,5 @@
>          // Without it, the trailing '/' will be escaped, and links from within
>          // that directory will be incorrect
>          escFlags = esc_Forced | esc_OnlyASCII | esc_AlwaysCopy | esc_FileBaseName | esc_Colon | esc_Directory;
>      }
> +    NS_EscapeURL(loc.get(), loc.Length(), escFlags, escapeBuf);

to make clear what |escapeBuf| is please rename it to locEscaped

@@ +895,5 @@
> +        // Try to convert non-ASCII bytes to Unicode using UTF-8 decoder.
> +        nsCOMPtr<nsIUnicodeDecoder> decoder =
> +            mozilla::dom::EncodingUtils::DecoderForEncoding("UTF-8");
> +        decoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Signal);
> +        int32_t len = escapeBuf.Length();

blank line over this line (try to split to blocks of logically belonging code)

@@ +898,5 @@
> +        decoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Signal);
> +        int32_t len = escapeBuf.Length();
> +        int32_t outlen = 0;
> +        rv = decoder->GetMaxLength(escapeBuf.get(), len, &outlen);
> +        if (NS_FAILED(rv)) return rv;

return rv on its own line

@@ +899,5 @@
> +        int32_t len = escapeBuf.Length();
> +        int32_t outlen = 0;
> +        rv = decoder->GetMaxLength(escapeBuf.get(), len, &outlen);
> +        if (NS_FAILED(rv)) return rv;
> +        nsAutoArrayPtr<PRUnichar> outbuf(new PRUnichar[outlen + 1]);

! check outlen is in <0,PR_MAX_INT32-1>, if not, return NS_ERROR_FAILURE.

@@ +904,5 @@
> +        rv = decoder->Convert(escapeBuf.get(), &len, outbuf, &outlen);
> +        // Use the result only if the sequence is valid as UTF-8.
> +        if (rv == NS_OK) {
> +            outbuf[outlen] = 0;
> +            utf16URI.Append(outbuf);

do utf16URI.Append(outbuf, outlen);
(In reply to Honza Bambas (:mayhemer) from comment #8)
> Tested with ftp://ftp.picosystems.net/
> Still 550 when switched to Shift_JIS, is that expected?

Yes, that's expected. The FTP directory listing has a bug about switching the encoding from the menu which is out of scope of this bug. Please change the default fallback encoding from Options-Content and reload the page to test. Also the second patch is needed.
I'll fix other points.
> ! check outlen is in <0,PR_MAX_INT32-1>, if not, return NS_ERROR_FAILURE.

|+ 1| was needed to make room for the trailing null byte. It was changed to |utf16URI.Append(outbuf, outlen);|, so outlen will no longer overflow.
Attachment #8338498 - Attachment is obsolete: true
Attachment #8338498 - Flags: review?(honzab.moz)
Attachment #8339898 - Flags: review?(honzab.moz)
Attachment #8339898 - Flags: review?(honzab.moz) → review+
Blocks: 297395
Comment on attachment 8339240 [details] [diff] [review]
Revert bug 427089

Stealing review on Michal's request.
Attachment #8339240 - Flags: review?(michal.novotny) → review?(honzab.moz)
(In reply to Masatoshi Kimura [:emk] from comment #6)
> Created attachment 8339240 [details] [diff] [review]
> Revert bug 427089
> 
> The "fix" for bug 427089 is totally broken. It prevented access to files in
> <ftp://ftp.picosystems.net/> (from bug 942495).
> I confirmed this didn't regress bug 427089.

How?  And I assume your fix is what fixes bug 427089 again?  What are other behavior changes when you back this patch out?  How this patch influences your patch?
Flags: needinfo?(VYV03354)
By the patch of bug 427089, <ftp://ftp.picosystems.net/pub/DATEL_%E7%B7%8F%E5%90%88%E3%82%AB%E3%82%BF%E3%83%AD%E3%82%B0_1986_87.pdf> is treated as the same URL as <ftp://ftp.picosystems.net/pub/DATEL_%91%8D%8D%87%83J%83%5E%83%8D%83O_1986_87.pdf> which is the cause of the 550 error.
This (UTF-8 to system charset) conversion was needed before my patch part 1 because non-ASCII path parts in URL were decoded using the system charset, then encoded back to UTF-8. But my patch made the non-ASCII bytes transparent, so the double conversion is breaking the access to file names which happens to be a valid sequence as UTF-8.
Flags: needinfo?(VYV03354)
> <ftp://ftp.picosystems.net/pub/DATEL_%E7%B7%8F%E5%90%88%E3%82%AB%E3%82%BF%E3%83%AD%E3%82%B0_1986_87.pdf> is treated as the same URL as <ftp://ftp.picosystems.net/pub/DATEL_%91%8D%8D%87%83J%83%5E%83%8D%83O_1986_87.pdf>

To be precise, it depends on the fallback charset. This is when the fallback charset is Shift_JIS.
Comment on attachment 8339240 [details] [diff] [review]
Revert bug 427089

Not locally tested.  FTP backout changes conform the original patch.
Attachment #8339240 - Flags: review?(honzab.moz) → review+
https://hg.mozilla.org/integration/mozilla-inbound/rev/6882f119dcb1
We will need a test infrastructure for the FTP directory listing...
Flags: in-testsuite?
Whiteboard: [leave open]
Hm, the status was not changed because of the word "revert"?
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla28
Comment on attachment 8339240 [details] [diff] [review]
Revert bug 427089

[Approval Request Comment]
Bug caused by (feature/regressing bug #): 427089
User impact if declined: Some files on FTP directory listings will not be accessible.
Testing completed (on m-c, etc.): landed on m-c, tested locally.
Risk to taking this patch (and alternatives if risky): pretty low
String or IDL/UUID changes made by this patch: none
Attachment #8339240 - Flags: approval-mozilla-aurora?
Missed the 28 train.
Target Milestone: mozilla28 → mozilla29
Attachment #8339240 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
Whiteboard: [qa-]
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: