History log of /haiku/src/add-ons/translators/stxt/STXTTranslator.cpp
Revision Date Author Comments
# 6199db56 31-Jul-2020 Michael Lotz <mmlr@mlotz.ch>

STXTTranslator: Fix use-after-free of encoding name.

The name retrieved from GetName() on BTextEncoding is owned by that
instance which goes out of scope when identify_text() returns. A const
char pointer to it can therefore not be used as an output variable. Use
a BString instead which ensures an appropriate reference is acquired.

Change-Id: Ib87fc9879d29e927bb41d1a9165ca7599b74a3bf
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3115
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 8bb5fd24 09-May-2020 Adrien Destugues <pulkomandy@pulkomandy.tk>

StyledText translator: use a larger buffer for encoding detection

It may be the case that a file is largely ASCII with few UTF-8 or
similar characters (typically, english text mentionning names in other
languages). It turns out 2 kilobytes of text is not enough for a safe
guess in that case.

Fixes #14674

Change-Id: Id894bebb821c22a17b776a71822d011abc795dea
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2628
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# be6c3343 19-Feb-2019 Murai Takashi <tmurai01@gmail.com>

STXTTranslator: Fix dead initialization

* Fix dead initialization at line 596. Pointed out
by clang static analyzer.
* As a result, 'BMallocIO encodingIO' at line 524
becomes unused, so delete it and header.

Change-Id: Ia62184fe0682a2eedeee42a513faccabdd3d1b59
Reviewed-on: https://review.haiku-os.org/c/1079
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>


# 5f5cc39c 11-Nov-2018 Augustin Cavalier <waddlesplash@gmail.com>

STXTTranslator: Fix truncated "be:encoding" attribute write.

Same issue as the mail_util fix.

Also while I'm here, alter behavior so that the Be-style attribute
gets overwritten with the Haiku-style one, instead of getting left
as is.

Should potentially help with #14674.


# f638c82a 29-Sep-2016 Adrien Destugues <pulkomandy@pulkomandy.tk>

StyledText: fix reading of utf-8 documents

BNode::ReadAttrString does not check for the attribute to actually be a
string. It will return B_OK (and useless data) if called on a
B_INT32_TYPE attribute. Check the attribute type before reading.

Also remove various debug ouput leftovers.

May fix #12976.


# a71b10d7 27-Sep-2016 Adrien Destugues <pulkomandy@pulkomandy.tk>

BTextEncoding: fix naming and move to BPrivate namespace.


# 08e52491 25-Sep-2016 Adrien Destugues <pulkomandy@pulkomandy.tk>

TextEncoding: add Encode/Decode methods.

This replaces convert_from/to_utf8 in a way that doesn't leak memory.

Use the new method in StyledEdit.

Fixes #6252, #3065.


# fbb725bb 25-Sep-2016 Adrien Destugues <pulkomandy@pulkomandy.tk>

Add text encoding detection to the Locale Kit.

As usual we ask ICU to do the actual work. The TextEncoding constructor
is fed with a sample of the text to identify (ICU docs recommend a few
hundred bytes). The text is analyzed in various ways (bytes patterns
such as UTF-8 escaping schemes, common letter sequences from known
languages, byte order marks) and an encoding is determined.

Replace code in StyledEdit by this new implementation.

Note that ICU seems to always return some valid encoding, even with fed
with obviously non-text data. This makes StyledEdit open the files no
matter what, where it would error out before.

Fixes #9395.


# e8eb40f7 12-Aug-2012 Humdinger <humdingerb@gmail.com>

Harmonized translator titles in DataTranslations.


# 2b861dd2 10-Aug-2012 Alex Smith <alex@alex-smith.me.uk>

Added translator add-ons.


# 546208a5 16-Apr-2012 Oliver Tappe <zooey@hirschkaefer.de>

More catalog-related cleanup.

* rename B_TRANSLATE_CONTEXT to B_TRANSLATION_CONTEXT and
B_TRANSLATE_WITH_CONTEXT to B_TRANSLATE_CONTEXT, squashing a TODO
* adjust all uses of both macros in Haiku's source tree
* use correct header guard for collecting/Catalog.h

The renamed macros require adjustments to all external applications
using catalogs.


# aec33db1 27-Nov-2011 Philippe Saint-Pierre <stpere@gmail.com>

Replace inappropriate usage of strncpy by strlcpy


# 3927bd3c 26-Nov-2011 Philippe Saint-Pierre <stpere@gmail.com>

Prevent string overflow by replacing usage of strcpy by strncpy

CID 8951, CID 10733, CID 10734, CID 10735, CID 10736, CID 10737, CID 10738,
CID 10739


# 70d59669 04-Feb-2011 Siarzhuk Zharski <zharik@gmx.li>

Applied following patches proposed by Jorma Karvonen:
#7135 #7140 #7141 #7145 #7186 #7188 #7191
#7136 #7187 #7184 #7185 #7192 #7138 #7139

with some changes and exclusions:
- all attempts to localize "fprintf(stderr,..." and "printf(..."
replaced by _untranslated_ "syslog(LOG_ERR ...";
- following *Translator.rdef files, that were not added in mentioned patches
were additionally created:
SGI, TIFF, RAW, RTF, PPM, WebP, EXR, STXT, WonderBrush, GIF, TGA;
- some small fixes for consistent catalogs building.

Thank you, Jorma! Please check. ;-)



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40357 a95241bf-73f2-0310-859d-f6bbb57e9c96


# bf243977 18-Jan-2011 Philippe Houdoin <philippe.houdoin@gmail.com>

Made local variables actually local.
Both JPEGTranslator and JPEG200Translator were "exporting" gSettings symbol,
which when loaded within a app (like Paladin) exporting the same global symbol
was leading to a symbol resolution error. See #7114 for details.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40245 a95241bf-73f2-0310-859d-f6bbb57e9c96


# fcc3e627 13-Jan-2010 Stephan Aßmus <superstippi@gmx.de>

Patch by Humdiner:
Changed strings in add-ons to sentence case. This is case-add-ons.diff
from #5169.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35046 a95241bf-73f2-0310-859d-f6bbb57e9c96


# fb3e35fc 22-Jan-2009 Michael Lotz <mmlr@mlotz.ch>

Fixing all headers/namespaces/name lookup problems that hinder a GCC 4.3.2
build. I sure hope that this doesn't break the build for anyone else.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28992 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e4ffdb7a 01-Mar-2008 Axel Dörfler <axeld@pinc-software.de>

* Added a more generic subtype for the source code files for automatic
MIME type guessing.
* Now, if the specific MIME type exists, it will be chosen, if it doesn't,
the generic MIME type is chosen. If that does not exist either, the most
generic is chosen (a.k.a. "text/plain").


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24187 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a878b1d9 11-Nov-2007 Stephan Aßmus <superstippi@gmx.de>

* remove superfluous tab


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22898 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1185d932 10-Nov-2007 Stephan Aßmus <superstippi@gmx.de>

* patch by vzsolt which really fixes the problem with zero byte buffers


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22895 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a9cde6d2 11-Nov-2007 Stephan Aßmus <superstippi@gmx.de>

* this should cover the case where the buffer is one byte long but is _not_
a text file


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22893 a95241bf-73f2-0310-859d-f6bbb57e9c96


# acdf38f6 11-Nov-2007 Stephan Aßmus <superstippi@gmx.de>

* fixed a bug researched by Varadi Zsolt Gyula, if the buffer is one byte long
or empty, assume text anyways, fixes Styled Edit opening empty files (#1610)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22892 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 7b93487d 23-Jan-2007 Axel Dörfler <axeld@pinc-software.de>

I accidently prevented the STXTTranslator from adding the styles section to the styled text output.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19932 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 691e54b4 16-Jan-2007 Axel Dörfler <axeld@pinc-software.de>

Minor fixes:
* the "state" variable was reset for each loop cycle.
* since the inner loop tested for "bytes" instead of "bytesLeft", convert_to_utf8()
was called twice for each chunk read.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19846 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 471c6cea 17-Jan-2007 Axel Dörfler <axeld@pinc-software.de>

* Added the file_ascmagic() stuff from our text sniffer add-on (originally taken from
BSD's file utility) to identify text files.
* The translator now automatically decodes files based "be:encoding" (which can now
also be a string type attribute), as well as whatever file_ascmagic() recognizes.
IOW we can now finally read all text files we recognize as text files.
* Added an ioExtension to force a specific encoding for Translate() (called "be:encoding"
as well).
* Enlarged the read buffer to 32768 bytes (instead of just 2048).
* Now fails when reading/writing files >4GB in STXT format (which doesn't support those)
* Translate() now writes the "be:encoding" attribute in case it detected the encoding
itself.
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19842 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 60e0ea9f 30-Aug-2006 Axel Dörfler <axeld@pinc-software.de>

Bug fix for my last commit: all of a sudden, a text would need more than one
bad character to be accepted.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18708 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d3669ef9 29-Aug-2006 Axel Dörfler <axeld@pinc-software.de>

* Extended the text recognition to UTF-8 characters - if a text contains too many
bad characters, it will be rejected, at least after bug #675 has been fixed.
* In the future, we should use the same mechanism as the TextSnifferAddon of the
registrar; it would also be nice to use additional charset information (at least
differentiating between latin-1 and UTF-8).
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18703 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9949213a 19-Oct-2005 Stephan Aßmus <superstippi@gmx.de>

removed the redundant "translator" from the folder names, fixed some warnings in the JPEG2000Translator

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14449 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e8eb40f7777e595c44f7148d072fb542c7b49ffa 12-Aug-2012 Humdinger <humdingerb@gmail.com>

Harmonized translator titles in DataTranslations.


# 2b861dd2a5a8129154c0c3003d816d2912890c27 10-Aug-2012 Alex Smith <alex@alex-smith.me.uk>

Added translator add-ons.


# 546208a53940a26c6379c48a7854ade1a8250fc5 16-Apr-2012 Oliver Tappe <zooey@hirschkaefer.de>

More catalog-related cleanup.

* rename B_TRANSLATE_CONTEXT to B_TRANSLATION_CONTEXT and
B_TRANSLATE_WITH_CONTEXT to B_TRANSLATE_CONTEXT, squashing a TODO
* adjust all uses of both macros in Haiku's source tree
* use correct header guard for collecting/Catalog.h

The renamed macros require adjustments to all external applications
using catalogs.


# aec33db178d1475aedf4ee37f385d4c85ed721a3 27-Nov-2011 Philippe Saint-Pierre <stpere@gmail.com>

Replace inappropriate usage of strncpy by strlcpy


# 3927bd3c0d16367eef862660f7b7a5309b66a5a1 26-Nov-2011 Philippe Saint-Pierre <stpere@gmail.com>

Prevent string overflow by replacing usage of strcpy by strncpy

CID 8951, CID 10733, CID 10734, CID 10735, CID 10736, CID 10737, CID 10738,
CID 10739


# 70d5966963513ff47a456ba70b7d2eec0f99648d 04-Feb-2011 Siarzhuk Zharski <zharik@gmx.li>

Applied following patches proposed by Jorma Karvonen:
#7135 #7140 #7141 #7145 #7186 #7188 #7191
#7136 #7187 #7184 #7185 #7192 #7138 #7139

with some changes and exclusions:
- all attempts to localize "fprintf(stderr,..." and "printf(..."
replaced by _untranslated_ "syslog(LOG_ERR ...";
- following *Translator.rdef files, that were not added in mentioned patches
were additionally created:
SGI, TIFF, RAW, RTF, PPM, WebP, EXR, STXT, WonderBrush, GIF, TGA;
- some small fixes for consistent catalogs building.

Thank you, Jorma! Please check. ;-)



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40357 a95241bf-73f2-0310-859d-f6bbb57e9c96


# bf243977ffd34197ad7c0820c2da5d21abea0402 18-Jan-2011 Philippe Houdoin <philippe.houdoin@gmail.com>

Made local variables actually local.
Both JPEGTranslator and JPEG200Translator were "exporting" gSettings symbol,
which when loaded within a app (like Paladin) exporting the same global symbol
was leading to a symbol resolution error. See #7114 for details.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40245 a95241bf-73f2-0310-859d-f6bbb57e9c96


# fcc3e627e1aedc4075deb952c66068d542fe9abe 13-Jan-2010 Stephan Aßmus <superstippi@gmx.de>

Patch by Humdiner:
Changed strings in add-ons to sentence case. This is case-add-ons.diff
from #5169.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35046 a95241bf-73f2-0310-859d-f6bbb57e9c96


# fb3e35fcec1ef41b413b3b121764509f436dee4d 22-Jan-2009 Michael Lotz <mmlr@mlotz.ch>

Fixing all headers/namespaces/name lookup problems that hinder a GCC 4.3.2
build. I sure hope that this doesn't break the build for anyone else.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28992 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e4ffdb7a9487618b72ffed0ddb3f046fd9288754 01-Mar-2008 Axel Dörfler <axeld@pinc-software.de>

* Added a more generic subtype for the source code files for automatic
MIME type guessing.
* Now, if the specific MIME type exists, it will be chosen, if it doesn't,
the generic MIME type is chosen. If that does not exist either, the most
generic is chosen (a.k.a. "text/plain").


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24187 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a878b1d91c7b123348d378a04df78d6005eaecbd 11-Nov-2007 Stephan Aßmus <superstippi@gmx.de>

* remove superfluous tab


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22898 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1185d9324050ebea77379d100a550adb6ab08fac 10-Nov-2007 Stephan Aßmus <superstippi@gmx.de>

* patch by vzsolt which really fixes the problem with zero byte buffers


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22895 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a9cde6d274a572a0e07abbef7833b9f30889dffa 11-Nov-2007 Stephan Aßmus <superstippi@gmx.de>

* this should cover the case where the buffer is one byte long but is _not_
a text file


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22893 a95241bf-73f2-0310-859d-f6bbb57e9c96


# acdf38f6630c2fffa81e3ccb788e3b9d838d53fb 11-Nov-2007 Stephan Aßmus <superstippi@gmx.de>

* fixed a bug researched by Varadi Zsolt Gyula, if the buffer is one byte long
or empty, assume text anyways, fixes Styled Edit opening empty files (#1610)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22892 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 7b93487d2d41ed4864221ba54fe4b4570e69dee6 23-Jan-2007 Axel Dörfler <axeld@pinc-software.de>

I accidently prevented the STXTTranslator from adding the styles section to the styled text output.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19932 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 691e54b4abb99b75211780a12a9329ba27230b2c 16-Jan-2007 Axel Dörfler <axeld@pinc-software.de>

Minor fixes:
* the "state" variable was reset for each loop cycle.
* since the inner loop tested for "bytes" instead of "bytesLeft", convert_to_utf8()
was called twice for each chunk read.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19846 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 471c6cea75b3381b13bcaf5abeb20ff17e2c5200 17-Jan-2007 Axel Dörfler <axeld@pinc-software.de>

* Added the file_ascmagic() stuff from our text sniffer add-on (originally taken from
BSD's file utility) to identify text files.
* The translator now automatically decodes files based "be:encoding" (which can now
also be a string type attribute), as well as whatever file_ascmagic() recognizes.
IOW we can now finally read all text files we recognize as text files.
* Added an ioExtension to force a specific encoding for Translate() (called "be:encoding"
as well).
* Enlarged the read buffer to 32768 bytes (instead of just 2048).
* Now fails when reading/writing files >4GB in STXT format (which doesn't support those)
* Translate() now writes the "be:encoding" attribute in case it detected the encoding
itself.
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19842 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 60e0ea9f7f7bd73304c1c737698e128ef432dfd6 30-Aug-2006 Axel Dörfler <axeld@pinc-software.de>

Bug fix for my last commit: all of a sudden, a text would need more than one
bad character to be accepted.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18708 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d3669ef9000a21e4eab4c91856246fab7b1c13c7 29-Aug-2006 Axel Dörfler <axeld@pinc-software.de>

* Extended the text recognition to UTF-8 characters - if a text contains too many
bad characters, it will be rejected, at least after bug #675 has been fixed.
* In the future, we should use the same mechanism as the TextSnifferAddon of the
registrar; it would also be nice to use additional charset information (at least
differentiating between latin-1 and UTF-8).
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18703 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9949213a25979d177b420bc71891c2bff02a331d 19-Oct-2005 Stephan Aßmus <superstippi@gmx.de>

removed the redundant "translator" from the folder names, fixed some warnings in the JPEG2000Translator

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14449 a95241bf-73f2-0310-859d-f6bbb57e9c96