shadowsocks / shadowsocks-windows

A C# port of shadowsocks
Other
58.5k stars 16.4k forks source link

Shadowsocks CRASHED and showed "Shadowsocks Non-UI Error" #1991

Closed michael2012z closed 5 years ago

michael2012z commented 6 years ago

Shadowsocks version / 影梭版本

4.1.1

Environment(Operating system, .NET Framework, etc) / 使用环境(操作系统,.NET Framework等)

Windows 7 SP1 .NET Framework 4.6.2

Steps you have tried / 操作步骤

The error happened immediately after Windows started up. A dialog with title "Shadowsocks Non-UI Error" appeared and Shadowsocks crashed.

What did you expect to see? / 期望的结果

It worked well.

What did you see instead? / 实际结果

Crashed.

Config and error log in detail (with all sensitive info masked) / 配置文件和日志文件(请隐去敏感信息)

Log:

[2018-08-31 06:45:50] Shadowsocks started (4.1.1)
[2018-08-31 06:45:50] 
=========================
Registered Encryptor Info
aes-128-cfb=>StreamOpenSSLEncryptor
aes-192-cfb=>StreamOpenSSLEncryptor
aes-256-cfb=>StreamOpenSSLEncryptor
aes-128-ctr=>StreamOpenSSLEncryptor
aes-192-ctr=>StreamOpenSSLEncryptor
aes-256-ctr=>StreamOpenSSLEncryptor
bf-cfb=>StreamOpenSSLEncryptor
camellia-128-cfb=>StreamOpenSSLEncryptor
camellia-192-cfb=>StreamOpenSSLEncryptor
camellia-256-cfb=>StreamOpenSSLEncryptor
rc4-md5=>StreamOpenSSLEncryptor
salsa20=>StreamSodiumEncryptor
chacha20=>StreamSodiumEncryptor
chacha20-ietf=>StreamSodiumEncryptor
aes-128-gcm=>AEADOpenSSLEncryptor
aes-192-gcm=>AEADOpenSSLEncryptor
aes-256-gcm=>AEADOpenSSLEncryptor
chacha20-ietf-poly1305=>AEADOpenSSLEncryptor
xchacha20-ietf-poly1305=>AEADSodiumEncryptor
=========================

[2018-08-31 06:45:50] [E] System.IndexOutOfRangeException: 索引超出了数组界限。
   在 Shadowsocks.Util.SystemProxy.Sysproxy.ParseQueryStr(String str)
   在 Shadowsocks.Util.SystemProxy.Sysproxy.SetIEProxy(Boolean enable, Boolean global, String proxyServer, String pacURL)
   在 Shadowsocks.Controller.SystemProxy.Update(Configuration config, Boolean forceDisable, PACServer pacSrv)
   在 Shadowsocks.Controller.ShadowsocksController.Reload()
   在 Shadowsocks.Program.Main()

Config:

{
  "configs": [
    {
      "server": "bj1-ult2.0ra0z.pw",
      "server_port": 3035,
      "password": "xxx",
      "method": "chacha20-ietf-poly1305",
      "plugin": "",
      "plugin_opts": "",
      "plugin_args": "",
      "remarks": "北京中转美国,Rate:2.00",
      "timeout": 5
    },
    {
      "server": "sh1-ult2.0ra0z.pw",
      "server_port": 3035,
      "password": "xxx",
      "method": "chacha20-ietf-poly1305",
      "plugin": "",
      "plugin_opts": "",
      "plugin_args": "",
      "remarks": "上海中转日本,Rate:2.00",
      "timeout": 5
    },
    {
      "server": "hz1-ult2.0ra0z.pw",
      "server_port": 3035,
      "password": "xxx",
      "method": "chacha20-ietf-poly1305",
      "plugin": "",
      "plugin_opts": "",
      "plugin_args": "",
      "remarks": "杭州中转香港,Rate:2.00",
      "timeout": 5
    },
    {
      "server": "sz1-ult2.0ra0z.pw",
      "server_port": 3035,
      "password": "xxx",
      "method": "chacha20-ietf-poly1305",
      "plugin": "",
      "plugin_opts": "",
      "plugin_args": "",
      "remarks": "深圳中转新加坡,Rate:2.00",
      "timeout": 5
    },
    {
      "server": "us1-ult2.0ra0z.pw",
      "server_port": 3035,
      "password": "xxx",
      "method": "chacha20-ietf-poly1305",
      "plugin": "",
      "plugin_opts": "",
      "plugin_args": "",
      "remarks": "美国,Rate:0.01",
      "timeout": 5
    },
    {
      "server": "tw1-ult2.0ra0z.pw",
      "server_port": 3035,
      "password": "xxx",
      "method": "chacha20-ietf-poly1305",
      "plugin": "",
      "plugin_opts": "",
      "plugin_args": "",
      "remarks": "台湾,Rate:1.00",
      "timeout": 5
    },
    {
      "server": "sg1-ult2.0ra0z.pw",
      "server_port": 3035,
      "password": "xxx",
      "method": "chacha20-ietf-poly1305",
      "plugin": "",
      "plugin_opts": "",
      "plugin_args": "",
      "remarks": "新加坡,Rate:1.00",
      "timeout": 5
    },
    {
      "server": "jp1-ult2.0ra0z.pw",
      "server_port": 3035,
      "password": "xxx",
      "method": "chacha20-ietf-poly1305",
      "plugin": "",
      "plugin_opts": "",
      "plugin_args": "",
      "remarks": "日本,Rate:1.50",
      "timeout": 5
    },
    {
      "server": "ru1-ult2.0ra0z.pw",
      "server_port": 3035,
      "password": "xxx",
      "method": "chacha20-ietf-poly1305",
      "plugin": "",
      "plugin_opts": "",
      "plugin_args": "",
      "remarks": "俄罗斯,Rate:1.20",
      "timeout": 5
    },
    {
      "server": "au1-ult2.0ra0z.pw",
      "server_port": 3035,
      "password": "xxx",
      "method": "chacha20-ietf-poly1305",
      "plugin": "",
      "plugin_opts": "",
      "plugin_args": "",
      "remarks": "澳大利亚,Rate:1.00",
      "timeout": 5
    },
    {
      "server": "hk1-ult2.0ra0z.pw",
      "server_port": 3035,
      "password": "xxx",
      "method": "chacha20-ietf-poly1305",
      "plugin": "",
      "plugin_opts": "",
      "plugin_args": "",
      "remarks": "香港1,Rate:1.00",
      "timeout": 5
    },
    {
      "server": "hk3-ult2.0ra0z.pw",
      "server_port": 3035,
      "password": "xxx",
      "method": "chacha20-ietf-poly1305",
      "plugin": "",
      "plugin_opts": "",
      "plugin_args": "",
      "remarks": "香港3,Rate:0.01",
      "timeout": 5
    },
    {
      "server": "hk4-ult2.0ra0z.pw",
      "server_port": 3035,
      "password": "xxx",
      "method": "chacha20-ietf-poly1305",
      "plugin": "",
      "plugin_opts": "",
      "plugin_args": "",
      "remarks": "香港4,Rate:1.20",
      "timeout": 5
    },
    {
      "server": "hk5-ult2.0ra0z.pw",
      "server_port": 3035,
      "password": "xxx",
      "method": "chacha20-ietf-poly1305",
      "plugin": "",
      "plugin_opts": "",
      "plugin_args": "",
      "remarks": "香港5,Rate:1.00",
      "timeout": 5
    }
  ],
  "strategy": null,
  "index": 7,
  "global": false,
  "enabled": true,
  "shareOverLan": false,
  "isDefault": false,
  "localPort": 1080,
  "portableMode": true,
  "pacUrl": null,
  "useOnlinePac": false,
  "secureLocalPac": true,
  "availabilityStatistics": false,
  "autoCheckUpdate": false,
  "checkPreRelease": false,
  "isVerboseLogging": false,
  "logViewer": {
    "topMost": false,
    "wrapText": false,
    "toolbarShown": false,
    "Font": "Consolas, 8pt",
    "BackgroundColor": "Black",
    "TextColor": "White"
  },
  "proxy": {
    "useProxy": false,
    "proxyType": 0,
    "proxyServer": "",
    "proxyPort": 0,
    "proxyTimeout": 3
  },
  "hotkey": {
    "SwitchSystemProxy": "",
    "SwitchSystemProxyMode": "",
    "SwitchAllowLan": "",
    "ShowLogs": "",
    "ServerMoveUp": "",
    "ServerMoveDown": "",
    "RegHotkeysAtStartup": false
  }
}
chenshaoju commented 6 years ago

Please hide your server address in the post.

Please read: https://github.com/shadowsocks/shadowsocks-windows/issues/1487#issuecomment-340370635

ghost commented 6 years ago

或许可以考虑取消sysproxy,改用c#实现,感觉这东西bug有点多……

celeron533 commented 6 years ago

@studentmain https://github.com/shadowsocks/shadowsocks-windows/issues/1662#issuecomment-363647836 sysproxy 当初参考自蓝灯的实现方式做的。wininet api调用需要binary arch与system arch一致。x86的ss-win运行在x64的系统上的话,直接嵌入pinvoke会有问题。sysproxy使用了简单粗暴的方式打破了这个限制。但由于是直接解析standard output的输出结果,特殊场景下会导致解析出错。

ghost commented 6 years ago

@celeron533 https://github.com/studentmain/SysProxyNet 还需要进一步研究,不过看上去能解决一些问题,至少是可以不用解析stdout了。

celeron533 commented 6 years ago

至少是可以不用解析stdout了

或者query 后还能提供其他参数做到每一行单独输出。如:

sysproxy query proxyserver
sysproxy query bypasslist
sysproxy query pac

之类的

在或者将输出结果以base64编码

sysproxy query base64
ghost commented 6 years ago

@celeron533 看了看,或许我把事情想复杂了。怀疑问题来源于sysproxy对Unicode环境的识别不稳定,某些情况会直接把Unicode(UTF16LE)输出出来。在解析失败后换个字符集再试试或者干脆直接把\0去掉再试应该可以解决问题,我等会去试试。

https://github.com/wongsyrone/sysproxy/blob/5604c85be1a18c1b01dcd5c089c012a9d49acac3/sysproxy/main.c#L226-L230

以下是利用Linux子系统触发bug的示例:

User@PC:/mnt/c/Apps/Shadowsocks/ss_win_temp$ ./sysproxy.exe query

 1 2 7 . 0 . 0 . 1 : 1 0 8 0
 < l o c a l > ; l o c a l h o s t ; 1 2 7 . * ; 1 0 . * ; 1 7 2 . 1 6 . * ; 1 7 2 . 1 7 . * ; 1 7 2 . 1 8 . * ; 1 7 2  1 9 . * ; 1 7 2 . 2 0 . * ; 1 7 2 . 2 1 . * ; 1 7 2 . 2 2 . * ; 1 7 2 . 2 3 . * ; 1 7 2 . 2 4 . * ; 1 7 2 . 2 5 . * ; 1 7 2 . 2 6 . * ; 1 7 2 . 2 7 . * ; 1 7 2 . 2 8 . * ; 1 7 2 . 2 9 . * ; 1 7 2 . 3 0 . * ; 1 7 2 . 3 1 . * ; 1 9 2 . 1 6 8   *
 ( n u l l ) User@PC:/mnt/c/Apps/Shadowsocks/ss_win_temp$ ./sysproxy.exe query | hd
00000000  33 00 0d 00 0a 00 31 00  32 00 37 00 2e 00 30 00  |3.....1.2.7...0.|
00000010  2e 00 30 00 2e 00 31 00  3a 00 31 00 30 00 38 00  |..0...1.:.1.0.8.|
00000020  30 00 0d 00 0a 00 3c 00  6c 00 6f 00 63 00 61 00  |0.....<.l.o.c.a.|
00000030  6c 00 3e 00 3b 00 6c 00  6f 00 63 00 61 00 6c 00  |l.>.;.l.o.c.a.l.|
00000040  68 00 6f 00 73 00 74 00  3b 00 31 00 32 00 37 00  |h.o.s.t.;.1.2.7.|
00000050  2e 00 2a 00 3b 00 31 00  30 00 2e 00 2a 00 3b 00  |..*.;.1.0...*.;.|
00000060  31 00 37 00 32 00 2e 00  31 00 36 00 2e 00 2a 00  |1.7.2...1.6...*.|
00000070  3b 00 31 00 37 00 32 00  2e 00 31 00 37 00 2e 00  |;.1.7.2...1.7...|
00000080  2a 00 3b 00 31 00 37 00  32 00 2e 00 31 00 38 00  |*.;.1.7.2...1.8.|
00000090  2e 00 2a 00 3b 00 31 00  37 00 32 00 2e 00 31 00  |..*.;.1.7.2...1.|
000000a0  39 00 2e 00 2a 00 3b 00  31 00 37 00 32 00 2e 00  |9...*.;.1.7.2...|
000000b0  32 00 30 00 2e 00 2a 00  3b 00 31 00 37 00 32 00  |2.0...*.;.1.7.2.|
000000c0  2e 00 32 00 31 00 2e 00  2a 00 3b 00 31 00 37 00  |..2.1...*.;.1.7.|
000000d0  32 00 2e 00 32 00 32 00  2e 00 2a 00 3b 00 31 00  |2...2.2...*.;.1.|
000000e0  37 00 32 00 2e 00 32 00  33 00 2e 00 2a 00 3b 00  |7.2...2.3...*.;.|
000000f0  31 00 37 00 32 00 2e 00  32 00 34 00 2e 00 2a 00  |1.7.2...2.4...*.|
00000100  3b 00 31 00 37 00 32 00  2e 00 32 00 35 00 2e 00  |;.1.7.2...2.5...|
00000110  2a 00 3b 00 31 00 37 00  32 00 2e 00 32 00 36 00  |*.;.1.7.2...2.6.|
00000120  2e 00 2a 00 3b 00 31 00  37 00 32 00 2e 00 32 00  |..*.;.1.7.2...2.|
00000130  37 00 2e 00 2a 00 3b 00  31 00 37 00 32 00 2e 00  |7...*.;.1.7.2...|
00000140  32 00 38 00 2e 00 2a 00  3b 00 31 00 37 00 32 00  |2.8...*.;.1.7.2.|
00000150  2e 00 32 00 39 00 2e 00  2a 00 3b 00 31 00 37 00  |..2.9...*.;.1.7.|
00000160  32 00 2e 00 33 00 30 00  2e 00 2a 00 3b 00 31 00  |2...3.0...*.;.1.|
00000170  37 00 32 00 2e 00 33 00  31 00 2e 00 2a 00 3b 00  |7.2...3.1...*.;.|
00000180  31 00 39 00 32 00 2e 00  31 00 36 00 38 00 2e 00  |1.9.2...1.6.8...|
00000190  2a 00 0d 00 0a 00 28 00  6e 00 75 00 6c 00 6c 00  |*.....(.n.u.l.l.|
000001a0  29 00                                             |).|
000001a2
celeron533 commented 6 years ago

@studentmain 非常感谢。但之前也有其他用户反应这个问题,然后他们清空系统代理设置后重新启用就没这个问题。不排除有些第三方代理工具也会修改proxy, bypasslist,然后在里面放入了奇怪的字符(或者是用户从网页复制bypasslist的时候带了特殊字符)

ghost commented 6 years ago

@celeron533 那我在那打个日志,如果两个字符集都解析失败,把sysproxy输出打下来,多收集点案例看看。

https://github.com/shadowsocks/shadowsocks-windows/blob/7e21e168cf5fffedec2f9688e5e15e1c4de494ea/shadowsocks-csharp/Util/SystemProxy/Sysproxy.cs#L195

不过按理说特殊字符只要不出现在\r\n中间都不会影响按行切割字符串。

celeron533 commented 5 years ago

主要还是有其他的代理软件给系统代理设置灌入了些奇怪的字符