nova-video-player / aos-AVP

NOVA opeN sOurce Video plAyer: main repository to build them all
Apache License 2.0
3.52k stars 201 forks source link

[Bug]: not support uri with ipv6 address host #1211

Closed noprofessional closed 4 months ago

noprofessional commented 5 months ago

Problem description

open with uri does not support uri with ipv6 address host.However, I am not sure whether this is a intentinal design or not.

I have found the code that cause this problem, however I am not sure whether this is a intentinal design or not. If this is intentional, feel free to close this issue.

In file aos-MediaLib/src/com/archos/mediacenter/filecoreextension/UriUtils.java

    private static final String HOSTNAME_PATTERN =
            "^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*$";

    public static boolean isValidHost(String hostname) {
        if (hostname == null) return false;
        Pattern pattern = Pattern.compile(HOSTNAME_PATTERN);
        Matcher matcher = pattern.matcher(hostname);
        return matcher.matches();
    }

The HOSTNAME_PATTERN does not match any string with : which exclude the ipv6 literal address.

Steps to reproduce the issue

choose Network shortcuts then menu on top-right corner, choose Add indexed foulder by URI in pop up window, input as follow (replace with valid global unicast address)

sftp://[<ipv6 literal>]:22/

press OK, and an error message

You must specify a valid remote address

Expected behavior

connect successfully.

Your phone/tablet/androidTV model

OnePlus 9R with ColorOs

Operating system version

Android 13

Application version and app store

6.2.71 from Google Play Store

Additional system information

No response

Debug logs

ip address is replace with ... for privacy reason

05-30 10:32:53.032 29298 29298 D com.archos.mediacenter.filecoreextension.UriUtils: isValidStringUri: input=sftp://[...]:22/ -> scheme=sftp host=[...] port=22 path=/
noprofessional commented 5 months ago

By the way, the logback.xml path in debug procedure really should be updated. I waste a lot of time trying to find the correct path.

/sdcard/Android/data/org.courville.nova/files/Android/data/org.courville.nova/files/logback/logback.xml

This is the one that works for me, and the log is output to logcat dirrectly not on nova.log as metioned in debug procedure. If my path is not working for you try find out path through

adb logcat --pid=$(adb shell pidof -s org.courville.nova) -b main | grep logback

and read include section in file aos-Video/src/noamazon/assets/logback.xml

courville commented 5 months ago

@noprofessional thanks for the insights. I will indeed update the debug procedure. It was made prior to API31 restrictions era. And I should probably simplify the path as well.

For track record:

// current solution
    private static final String HOSTNAME_PATTERN =
            "^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*$";

// evolution proposed

    private static final String HOSTNAME_PATTERN =
            "^(?=.{1,255}$)([0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*$|" +  // FQDN
                    "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$|" +  // IPv4
                    "^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$";  // Simplified IPv6

// alternatives

    private static final String HOSTNAME_PATTERN =
            "^(?=.{1,255}$)([0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*|" + // FQDN
                    "\\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b|" + // IPv4
                    "\\b(?:(?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}|::(?:[0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4}|(?:[0-9A-Fa-f]{1,4}:){1,6}:|::)$"; // IPv6

    private static final String HOST_PATTERN = "^" +
            "(?:" +                                    // Group for either IP or hostname
            "(" +                                     // Group 1: IPv4
            "(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\." +
            "(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\." +
            "(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\." +
            "(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)" +
            ")" +
            "|" +                                      // OR
            "(" +                                     // Group 2: IPv6 (abbreviated)
            "(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}" +
            ")" +
            "|" +                                      // OR
            "(" +                                     // Group 3: FQDN (simplified)
            "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]\\." + // Label (max 63 chars)
            "(?:[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]\\.)*" + // Other labels
            "[a-zA-Z]{2,}" +                           // TLD (min 2 chars)
            ")" +
            ")$" +                                     // End of group and input
            "";
noprofessional commented 5 months ago

Just a friendly reminder, IPv6 addresses may be enclosed in square brackets.

courville commented 5 months ago

Please try Please test https://github.com/nova-video-player/aos-AVP/releases/tag/v6.2.80 It is not working yet for link-local addresses.

courville commented 5 months ago

Note to self: link-local with scope_id_delimiter is supported in https://github.com/apache/httpcomponents-core/blob/master/httpcore5/src/main/java/org/apache/hc/core5/net/InetAddressUtils.java but this is for 5.3-alpha release and current 5.2.4 does not support link-local addresses check yet. It will thus come "automagically" later when updating dependancies. IPv6 and IPv4 checks are not delegated to external httpcore5 apache library (that was already included).