You are not logged in.

#1 2015-05-21 03:12:25

Sanbanyo
Member
Registered: 2015-04-23
Posts: 2

Issue with Japanese characters in files/filenames in terminal.

I recently downloaded a zip file with Japanese characters in the archive and in the files within the archive. The name of the archive is "【批量下载】パノプティコン労働歌 第一等.zip"

The characters are properly displayed in firefox, chrome, and other applications, but in my terminal some of the characters appear corrupted. Screenshot: https://i.imgur.com/4R22m0D.png

Additionally, this leads to corruption of the files in the archive. When I try to extract the files, this is what happens:

% unzip 【批量下载】パノプティコン労働歌 第一等.zip 
Archive:  【批量下载】パノプティコン労働歌 第一等.zip
 extracting: +ii/flac/Let's -+-ʦ1,000,000-.flac   bad CRC 5f603d51  (should be debde980)
 extracting: +ii/flac/+ѦѾP++ -instrumental-.flac   bad CRC 78b93a2d  (should be 3501d555)
 extracting: +ii/flac/----.flac   bad CRC ddeb1d3e  (should be c05ae84f)
 extracting: +ii/flac/+ѦѾP++.flac   bad CRC 0ccf2725  (should be be2b58f1)
 extracting: +ii/flac/Let's -+-ʦ1,000,000--instrumental-.flac   bad CRC 67a39f8e  (should be ece37917)
 extracting: +ii/flac/.flac   bad CRC f90f3aa0  (should be 41756c2c)
 extracting: +ii/flac/ -instrumental-.flac   bad CRC 3be03344  (should be 0b7a9cea)
 extracting: +ii/flac/---- -instrumental-.flac   bad CRC 569b6194  (should be adb5d5fe)

I'm not sure what could be the cause of this. I'm using uxterm with terminus as my main font and IPA gothic (a Japanese font) as my secondary font. I have a Japanese locale set up and have tried setting LANG=ja_JP.utf8 before, but the results never change.

Also, this issue isn't just with this file. This happens with nearly all archives that have Japanese characters associated with it.

Has anyone encountered this issue before or knows what might be wrong?

Last edited by Sanbanyo (2015-05-21 03:12:56)

Offline

#2 2015-05-21 04:55:37

jamdox
Member
Registered: 2015-05-02
Posts: 48

Re: Issue with Japanese characters in files/filenames in terminal.

I'll piggy-back on this post since I'm having similar problems with some korean files.

I went to /etc/locales.gen and enabled the korean encodings, ran locale-gen, and no joy.  I tried making sure the LC_CTYPE was the korean UTF8 and no joy. (side note, it seems localectl didn't change the var, I had to put "LC_CTYPE="ko_KR...." before the cp command.

It's giving me a "cp: cannot stat: foo: no such file or directory" error.

Very frustrating.

Offline

#3 2015-05-21 09:01:34

ugjka
Member
From: Latvia
Registered: 2014-04-01
Posts: 1,962
Website

Re: Issue with Japanese characters in files/filenames in terminal.

It's a known problem with zip.

https://marcosc.com/2008/12/zip-files-a … -hate-you/

Consider, when a zip file is created on Linux, it just writes the bytes for the file name in the encoding of the underlying file system. So, if the file system is in ISO-8859-1, the bytes are written in ISO-8859-1. This may seem ok, but when you decompress the zip file on Windows, which runs on encoding Windows-1252, the file names get all mangled. If the underlying encoding of the file system on Linux is something else, you won’t be able to share files with other systems at all. So in this case, it is not Window’s fault.

The Zip spec says that the only supported encodings are CP437 and UTF-8, but everyone has ignored that. Implementers just encode file names however they want (usually byte for byte as they are in the OS… see table below).

Offline

#4 2015-05-21 18:37:50

Sanbanyo
Member
Registered: 2015-04-23
Posts: 2

Re: Issue with Japanese characters in files/filenames in terminal.

I see. So there's nothing I can do?

Offline

#5 2015-05-21 23:02:49

jsoy9pQbYVNu5nfU
Member
Registered: 2013-04-19
Posts: 108

Re: Issue with Japanese characters in files/filenames in terminal.

Maybe 7zip or another tool has workarounds for broken file names, you could try that.

Or you could try to go over the files in the zip archive one-by-one and write it to files out-1, out-2, ..., out-$n without concerning yourself with the file names. You could get file endings back via the mimetype.

This script might work:

#include <stdio.h>
#include <zip.h>

static const char *template = "./out-%04d.bin";

int main(int argc, char**argv)
{
  int err = 0;
  zip_t *arc = zip_open((const char*)argv[1], ZIP_RDONLY, &err);

  if(arc == NULL)
  {
    printf("Failed to open ZIP, error %d\n", err);
    return -1;
  }

  zip_int64_t n = zip_get_num_entries(arc, 0);

  printf("%s: # of packed files: %d\n", argv[1], n);

  for(int i = 0; i < n; i++)
  {
    zip_stat_t stat;
    zip_stat_index(arc, i, ZIP_FL_UNCHANGED, &stat);
    char buf[stat.size];
    char oname[sizeof(template)];

    zip_file_t *f = zip_fopen_index(arc, (zip_int64_t)i, ZIP_FL_UNCHANGED);
    zip_fread(f, (void*)&buf[0], stat.size);

    snprintf(&oname[0], sizeof(template), template, i);
    FILE *of = fopen(oname, "wb");
    fwrite(&buf[0], stat.size, 1, of);

    printf("%s: %s => %lu bytes\n", argv[1], oname, stat.size); 

    zip_fclose(f);
    fclose(of);
  }

  zip_close(arc);

  return 0;
}

Compile with

gcc -std=gnu99 -O3 -o unzip unzip.c -lzip

and run as

./unzip $funnyzipfile

You should get template-named, numbered output files in the current directory.

Last edited by jsoy9pQbYVNu5nfU (2015-05-21 23:09:29)

Offline

#6 2015-05-22 11:48:49

Soukyuu
Member
Registered: 2014-04-08
Posts: 854

Re: Issue with Japanese characters in files/filenames in terminal.

I don't know if it works, but if you know the original language used in filenames, can't you start the program prefixed with the language?

LANG=ja_JP unzip 【批量下载】パノプティコン労働歌 第一等.zip

There are several variations to try, .utf-8 won't work, but EUC something and shift_JIS should be an option. Not on linux atm, take a look at /etc/locale.gen for exact encoding names.


[ Arch x86_64 | linux | Framework 13 | AMD Ryzen™ 5 7640U | 32GB RAM | KDE Plasma Wayland ]

Offline

#7 2015-05-22 17:31:12

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,615

Re: Issue with Japanese characters in files/filenames in terminal.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

Board footer

Powered by FluxBB