Guest User

Untitled

a guest
Oct 18th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.56 KB | None | 0 0
  1. --- a/src/gui/text/qzip.cpp
  2. +++ b/src/gui/text/qzip.cpp
  3. @@ -416,7 +416,9 @@ public:
  4.  void QZipPrivate::fillFileInfo(int index, QZipReader::FileInfo &fileInfo) const
  5.  {
  6.      FileHeader header = fileHeaders.at(index);
  7. -    fileInfo.filePath = QString::fromLocal8Bit(header.file_name);
  8. +    // if bit 11 is set, the filename and comment fields must be encoded using UTF-8
  9. +    const bool inUtf8 = (readUShort(header.h.general_purpose_bits) & 0x0800) != 0;
  10. +    fileInfo.filePath = inUtf8 ? QString::fromUtf8(header.file_name) : QString::fromLocal8Bit(header.file_name);
  11.      const quint32 mode = (qFromLittleEndian<quint32>(&header.h.external_file_attributes[0]) >> 16) & 0xFFFF;
  12.      fileInfo.isDir = S_ISDIR(mode);
  13.      fileInfo.isFile = S_ISREG(mode);
  14. @@ -629,7 +631,12 @@ void QZipWriterPrivate::addEntry(EntryType type, const QString &fileName, const
  15.      crc_32 = ::crc32(crc_32, (const uchar *)contents.constData(), contents.length());
  16.      writeUInt(header.h.crc_32, crc_32);
  17.  
  18. -    header.file_name = fileName.toLocal8Bit();
  19. +    // if bit 11 is set, the filename and comment fields must be encoded using UTF-8
  20. +    ushort general_purpose_bits = 0x0800; // always use utf-8
  21. +    writeUShort(header.h.general_purpose_bits, general_purpose_bits);
  22. +
  23. +    const bool inUtf8 = (general_purpose_bits & 0x0800) != 0;
  24. +    header.file_name = inUtf8 ? fileName.toUtf8() : fileName.toLocal8Bit();
  25.      if (header.file_name.size() > 0xffff) {
  26.          qWarning("QZip: Filename too long, chopping it to 65535 characters");
  27.          header.file_name = header.file_name.left(0xffff);
Add Comment
Please, Sign In to add comment