douyangcheng4965 2017-07-13 15:07
浏览 33
已采纳

在Go中无法读取大于1024个字符的输入

I am using fmt.Scanf to read a string input in Golang. But the command stalls when we pass in a large input (>1024 characters). I am using Go version go1.8.3 darwin/amd64.

Here is the code

package main

import "fmt"

func main() {
    var s string
    fmt.Scanf("%s", &s)
    fmt.Println(s)
}

Here is the payload that fails https://pastebin.com/raw/fJ4QAZUZ

Go seems to take input till Jy in that payload which marks 1024 number of characters. So is 1024 a limit or what?

PS - I had already tampered the encoded cookie at that link, so no worries.

  • 写回答

1条回答 默认 最新

  • dqqyp90576 2017-07-13 15:19
    关注

    It's not the limit of the fmt package or fmt.Scanf(), this example properly scans more than 3KB:

    // src is a looooong text (>3KB)
    
    var s string
    fmt.Println(len(src))
    fmt.Sscanf(src, "%s", &s)
    fmt.Println(len(s))
    

    Try it on the Go Playground

    It's most likely the limit of your terminal. I also tried your unmodified version, pasted more than 10KB of text, and the result was 4096 bytes (Ubuntu linux 16.04, Bash).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 商城生产日期批次库存问题
  • ¥15 esp8266控制共阳极wrgb灯板无法关闭所有led灯
  • ¥100 python读取速度问题
  • ¥15 stm32f407使用DMA问题
  • ¥15 您好 这个API接口该怎么弄 网站搭建好了 API也有 现在就不知道该怎么填写API 不知道怎么用
  • ¥88 用uniapp写一个多端的程序,用到高德地图,用高德的JSAPI吗?
  • ¥20 关于#c++#的问题:水果店管理系统
  • ¥30 dbLinq最新版linq sqlite
  • ¥20 对D盘进行分盘之前没有将visual studio2022卸载掉,现在该如何下载回来
  • ¥15 完成虚拟机环境配置,还有安装kettle